Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/5387.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`opentelemetry-exporter-otlp-common`: remove dependency on incubating attributes from OTLP exporters
1 change: 1 addition & 0 deletions docs/getting_started/tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ wrapt==1.15.0
-e opentelemetry-proto
-e exporter/opentelemetry-exporter-otlp-proto-common
-e exporter/opentelemetry-exporter-otlp-proto-grpc
-e exporter/opentelemetry-exporter-otlp-common
-e opentelemetry-api
-e opentelemetry-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ classifiers = [
"Programming Language :: Python :: 3.14",
]
dependencies = [
"opentelemetry-api ~= 1.15",
"opentelemetry-sdk ~= 1.44.0.dev",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,22 @@
from time import perf_counter
from typing import TYPE_CHECKING, Protocol

from opentelemetry.metrics import MeterProvider, get_meter_provider
from opentelemetry.semconv._incubating.attributes.otel_attributes import (
OTEL_COMPONENT_NAME,
OTEL_COMPONENT_TYPE,
from opentelemetry.exporter.otlp.common._exporter_metrics.semconv import (
_ERROR_TYPE,
_OTEL_COMPONENT_NAME,
_OTEL_COMPONENT_TYPE,
_SERVER_ADDRESS,
_SERVER_PORT,
OtelComponentTypeValues,
_create_otel_sdk_exporter_log_exported,
_create_otel_sdk_exporter_log_inflight,
_create_otel_sdk_exporter_metric_data_point_exported,
_create_otel_sdk_exporter_metric_data_point_inflight,
_create_otel_sdk_exporter_operation_duration,
_create_otel_sdk_exporter_span_exported,
_create_otel_sdk_exporter_span_inflight,
)
from opentelemetry.semconv._incubating.metrics.otel_metrics import (
create_otel_sdk_exporter_log_exported,
create_otel_sdk_exporter_log_inflight,
create_otel_sdk_exporter_metric_data_point_exported,
create_otel_sdk_exporter_metric_data_point_inflight,
create_otel_sdk_exporter_operation_duration,
create_otel_sdk_exporter_span_exported,
create_otel_sdk_exporter_span_inflight,
)
from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE
from opentelemetry.semconv.attributes.server_attributes import (
SERVER_ADDRESS,
SERVER_PORT,
)
from opentelemetry.metrics import MeterProvider, get_meter_provider

if TYPE_CHECKING:
from typing import Literal
Expand All @@ -54,6 +50,7 @@ def export_operation(

class NoOpExporterMetrics:
@contextmanager
# pylint: disable-next=no-self-use
def export_operation(self, num_items: int) -> Iterator[ExportResult]:
yield ExportResult()

Expand All @@ -66,20 +63,6 @@ def __init__(
endpoint: UrlParseResult,
meter_provider: MeterProvider | None,
) -> None:
if signal == "traces":
create_exported = create_otel_sdk_exporter_span_exported
create_inflight = create_otel_sdk_exporter_span_inflight
elif signal == "logs":
create_exported = create_otel_sdk_exporter_log_exported
create_inflight = create_otel_sdk_exporter_log_inflight
else:
create_exported = (
create_otel_sdk_exporter_metric_data_point_exported
)
create_inflight = (
create_otel_sdk_exporter_metric_data_point_inflight
)

port = endpoint.port
if port is None:
if endpoint.scheme == "https":
Expand All @@ -93,19 +76,31 @@ def __init__(
count = _component_counter[component_type_value]
_component_counter[component_type_value] = count + 1
self._standard_attrs: dict[str, AttributeValue] = {
OTEL_COMPONENT_TYPE: component_type_value,
OTEL_COMPONENT_NAME: f"{component_type_value}/{count}",
_OTEL_COMPONENT_TYPE: component_type_value,
_OTEL_COMPONENT_NAME: f"{component_type_value}/{count}",
}
if endpoint.hostname:
self._standard_attrs[SERVER_ADDRESS] = endpoint.hostname
self._standard_attrs[_SERVER_ADDRESS] = endpoint.hostname
if port is not None:
self._standard_attrs[SERVER_PORT] = port
self._standard_attrs[_SERVER_PORT] = port

meter_provider = meter_provider or get_meter_provider()
meter = meter_provider.get_meter("opentelemetry-sdk")
self._inflight = create_inflight(meter)
self._exported = create_exported(meter)
self._duration = create_otel_sdk_exporter_operation_duration(meter)
self._duration = _create_otel_sdk_exporter_operation_duration(meter)
match signal:
case "traces":
self._inflight = _create_otel_sdk_exporter_span_inflight(meter)
self._exported = _create_otel_sdk_exporter_span_exported(meter)
case "logs":
self._inflight = _create_otel_sdk_exporter_log_inflight(meter)
self._exported = _create_otel_sdk_exporter_log_exported(meter)
case _:
self._inflight = (
_create_otel_sdk_exporter_metric_data_point_inflight(meter)
)
self._exported = (
_create_otel_sdk_exporter_metric_data_point_exported(meter)
)

@contextmanager
def export_operation(self, num_items: int) -> Iterator[ExportResult]:
Expand All @@ -122,7 +117,7 @@ def export_operation(self, num_items: int) -> Iterator[ExportResult]:
end_time = perf_counter()
self._inflight.add(-num_items, self._standard_attrs)
exported_attrs = (
{**self._standard_attrs, ERROR_TYPE: type(error).__qualname__}
{**self._standard_attrs, _ERROR_TYPE: type(error).__qualname__}
if error
else self._standard_attrs
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

# TODO: This file should be removed once the exporter specific
# metrics become stable (i.e. they are no longer incubating)

from __future__ import annotations

from enum import Enum
from typing import TYPE_CHECKING, Final

if TYPE_CHECKING:
from opentelemetry.metrics import Counter, Histogram, Meter, UpDownCounter

# TODO: Remove these attributes once "opentelemetry-semantic-conventions"
# becomes stable (i.e. reaches 1.x.y)
_ERROR_TYPE: Final[str] = "error.type"
_SERVER_ADDRESS: Final[str] = "server.address"
_SERVER_PORT: Final[str] = "server.port"


class OtelComponentTypeValues(Enum):
OTLP_GRPC_SPAN_EXPORTER = "otlp_grpc_span_exporter"
OTLP_HTTP_SPAN_EXPORTER = "otlp_http_span_exporter"
OTLP_HTTP_JSON_SPAN_EXPORTER = "otlp_http_json_span_exporter"
ZIPKIN_HTTP_SPAN_EXPORTER = "zipkin_http_span_exporter"
OTLP_GRPC_LOG_EXPORTER = "otlp_grpc_log_exporter"
OTLP_HTTP_LOG_EXPORTER = "otlp_http_log_exporter"
OTLP_HTTP_JSON_LOG_EXPORTER = "otlp_http_json_log_exporter"
OTLP_GRPC_METRIC_EXPORTER = "otlp_grpc_metric_exporter"
OTLP_HTTP_METRIC_EXPORTER = "otlp_http_metric_exporter"
OTLP_HTTP_JSON_METRIC_EXPORTER = "otlp_http_json_metric_exporter"
PROMETHEUS_HTTP_TEXT_METRIC_EXPORTER = (
"prometheus_http_text_metric_exporter"
)


_OTEL_COMPONENT_NAME: Final[str] = "otel.component.name"
_OTEL_COMPONENT_TYPE: Final[str] = "otel.component.type"

_OTEL_SDK_EXPORTER_SPAN_EXPORTED: Final[str] = (
"otel.sdk.exporter.span.exported"
)
_OTEL_SDK_EXPORTER_SPAN_INFLIGHT: Final[str] = (
"otel.sdk.exporter.span.inflight"
)
_OTEL_SDK_EXPORTER_LOG_EXPORTED: Final[str] = "otel.sdk.exporter.log.exported"
_OTEL_SDK_EXPORTER_LOG_INFLIGHT: Final[str] = "otel.sdk.exporter.log.inflight"
_OTEL_SDK_EXPORTER_METRIC_DATA_POINT_EXPORTED: Final[str] = (
"otel.sdk.exporter.metric_data_point.exported"
)
_OTEL_SDK_EXPORTER_METRIC_DATA_POINT_INFLIGHT: Final[str] = (
"otel.sdk.exporter.metric_data_point.inflight"
)
_OTEL_SDK_EXPORTER_OPERATION_DURATION: Final[str] = (
"otel.sdk.exporter.operation.duration"
)


def _create_otel_sdk_exporter_span_exported(meter: Meter) -> Counter:
return meter.create_counter(
name=_OTEL_SDK_EXPORTER_SPAN_EXPORTED,
description="The number of spans for which the export has finished, either successful or failed.",
unit="{span}",
)


def _create_otel_sdk_exporter_span_inflight(meter: Meter) -> UpDownCounter:
return meter.create_up_down_counter(
name=_OTEL_SDK_EXPORTER_SPAN_INFLIGHT,
description="The number of spans which were passed to the exporter, but that have not been exported yet (neither successful, nor failed).",
unit="{span}",
)


def _create_otel_sdk_exporter_log_exported(meter: Meter) -> Counter:
return meter.create_counter(
name=_OTEL_SDK_EXPORTER_LOG_EXPORTED,
description="The number of log records for which the export has finished, either successful or failed.",
unit="{log_record}",
)


def _create_otel_sdk_exporter_log_inflight(meter: Meter) -> UpDownCounter:
return meter.create_up_down_counter(
name=_OTEL_SDK_EXPORTER_LOG_INFLIGHT,
description="The number of log records which were passed to the exporter, but that have not been exported yet (neither successful, nor failed).",
unit="{log_record}",
)


def _create_otel_sdk_exporter_metric_data_point_exported(
meter: Meter,
) -> Counter:
return meter.create_counter(
name=_OTEL_SDK_EXPORTER_METRIC_DATA_POINT_EXPORTED,
description="The number of metric data points for which the export has finished, either successful or failed.",
unit="{data_point}",
)


def _create_otel_sdk_exporter_metric_data_point_inflight(
meter: Meter,
) -> UpDownCounter:
return meter.create_up_down_counter(
name=_OTEL_SDK_EXPORTER_METRIC_DATA_POINT_INFLIGHT,
description="The number of metric data points which were passed to the exporter, but that have not been exported yet (neither successful, nor failed).",
unit="{data_point}",
)


def _create_otel_sdk_exporter_operation_duration(meter: Meter) -> Histogram:
return meter.create_histogram(
name=_OTEL_SDK_EXPORTER_OPERATION_DURATION,
description="The duration of exporting a batch of telemetry records.",
unit="s",
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
from unittest.mock import Mock, patch
from urllib.parse import urlparse

from opentelemetry.exporter.otlp.proto.common._exporter_metrics import (
from opentelemetry.exporter.otlp.common._exporter_metrics import (
ExporterMetrics,
NoOpExporterMetrics,
create_exporter_metrics,
)
from opentelemetry.semconv._incubating.attributes.otel_attributes import (
OtelComponentTypeValues,
create_exporter_metrics,
)


Expand All @@ -20,7 +18,7 @@ def test_factory_returns_noop_when_disabled(self):
meter_provider = Mock()

with patch(
"opentelemetry.exporter.otlp.proto.common."
"opentelemetry.exporter.otlp.common."
"_exporter_metrics.get_meter_provider"
) as get_meter_provider:
metrics = create_exporter_metrics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies = [
"opentelemetry-api ~= 1.15",
"opentelemetry-proto == 1.44.0.dev",
"opentelemetry-sdk ~= 1.44.0.dev",
"opentelemetry-exporter-otlp-common == 0.65b0.dev",
"opentelemetry-exporter-otlp-proto-common == 1.44.0.dev",
"typing-extensions >= 4.6.0",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from typing import Literal

from grpc import ChannelCredentials, Compression, StatusCode
from opentelemetry.exporter.otlp.common._exporter_metrics import (
OtelComponentTypeValues,
)
from opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs
from opentelemetry.exporter.otlp.proto.grpc.exporter import (
OTLPExporterMixin,
Expand Down Expand Up @@ -36,9 +39,6 @@
OTEL_EXPORTER_OTLP_LOGS_INSECURE,
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT,
)
from opentelemetry.semconv._incubating.attributes.otel_attributes import (
OtelComponentTypeValues,
)


class OTLPLogExporter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
secure_channel,
ssl_channel_credentials,
)
from opentelemetry.exporter.otlp.proto.common._exporter_metrics import (
from opentelemetry.exporter.otlp.common._exporter_metrics import (
OtelComponentTypeValues,
create_exporter_metrics,
)
from opentelemetry.exporter.otlp.proto.common._internal import (
Expand Down Expand Up @@ -98,9 +99,6 @@
from opentelemetry.sdk.resources import Resource as SDKResource
from opentelemetry.sdk.trace import ReadableSpan
from opentelemetry.sdk.trace.export import SpanExportResult
from opentelemetry.semconv._incubating.attributes.otel_attributes import (
OtelComponentTypeValues,
)
from opentelemetry.semconv._incubating.attributes.rpc_attributes import (
RPC_RESPONSE_STATUS_CODE,
)
Comment thread
herin049 marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from os import environ

from grpc import ChannelCredentials, Compression, StatusCode
from opentelemetry.exporter.otlp.common._exporter_metrics import (
OtelComponentTypeValues,
)
from opentelemetry.exporter.otlp.proto.common._internal.metrics_encoder import (
OTLPMetricExporterMixin,
)
Expand Down Expand Up @@ -63,9 +66,6 @@
from opentelemetry.sdk.metrics.export import ( # noqa: F401
Histogram as HistogramType,
)
from opentelemetry.semconv._incubating.attributes.otel_attributes import (
OtelComponentTypeValues,
)

_logger = getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from os import environ

from grpc import ChannelCredentials, Compression, StatusCode
from opentelemetry.exporter.otlp.common._exporter_metrics import (
OtelComponentTypeValues,
)
from opentelemetry.exporter.otlp.proto.common.trace_encoder import (
encode_spans,
)
Expand Down Expand Up @@ -49,9 +52,6 @@
)
from opentelemetry.sdk.trace import ReadableSpan
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
from opentelemetry.semconv._incubating.attributes.otel_attributes import (
OtelComponentTypeValues,
)

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ protobuf>=5.29.5
pytest>=7.4.4
-e opentelemetry-api
-e tests/opentelemetry-test-utils
-e exporter/opentelemetry-exporter-otlp-common
-e exporter/opentelemetry-exporter-otlp-proto-common
-e opentelemetry-proto
-e opentelemetry-sdk
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# This file was autogenerated by uv via the following command:
# uv pip compile --python 3.10 --universal -c dev-requirements.txt exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in -o exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.latest.txt
-e exporter/opentelemetry-exporter-otlp-common
# via
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
# opentelemetry-exporter-otlp-proto-grpc
-e exporter/opentelemetry-exporter-otlp-proto-common
# via
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
Expand All @@ -9,6 +13,7 @@
-e opentelemetry-api
# via
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
# opentelemetry-exporter-otlp-common
# opentelemetry-exporter-otlp-proto-grpc
# opentelemetry-sdk
# opentelemetry-semantic-conventions
Expand All @@ -21,6 +26,7 @@
-e opentelemetry-sdk
# via
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
# opentelemetry-exporter-otlp-common
# opentelemetry-exporter-otlp-proto-grpc
# opentelemetry-test-utils
-e opentelemetry-semantic-conventions
Expand Down
Loading
Loading