Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set schema_url on all tracers and meters #1977

Merged
merged 9 commits into from
Nov 6, 2023
Merged
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1800](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1800))

### Added

- `opentelemetry-instrumentation-botocore` Include SNS topic ARN as a span attribute with name `messaging.destination.name` to uniquely identify the SNS topic
([#1995](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1995))
- `opentelemetry-instrumentation-system-metrics` Add support for collecting process metrics
([#1948](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1948))
- Added schema_url (`"https://opentelemetry.io/schemas/1.11.0"`) to all metrics and traces
([#1977](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1977))

### Fixed

Expand Down Expand Up @@ -61,7 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1744](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1744))
- Fix async redis clients not being traced correctly
([#1830](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1830))
- Make Flask request span attributes available for `start_span`.
- Make Flask request span attributes available for `start_span`.
([#1784](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1784))
- Fix falcon instrumentation's usage of Span Status to only set the description if the status code is ERROR.
([#1840](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1840))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ async def wrapper(wrapped, instance, args, kwargs):
def _instrument(self, **kwargs):
tracer_provider = kwargs.get("tracer_provider", None)
tracer = trace.get_tracer(
_INSTRUMENTATION_MODULE_NAME, __version__, tracer_provider
_INSTRUMENTATION_MODULE_NAME,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
self._instrument_queue(tracer)
self._instrument_exchange(tracer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ def create_trace_config(
# Explicitly specify the type for the `request_hook` and `response_hook` param and rtype to work
# around this issue.

tracer = get_tracer(__name__, __version__, tracer_provider)
tracer = get_tracer(
__name__,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

def _end_trace(trace_config_ctx: types.SimpleNamespace):
context_api.detach(trace_config_ctx.token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ def test_status_codes(self):

self.memory_exporter.clear()

def test_schema_url(self):
with self.subTest(status_code=200):
host, port = self._http_request(
trace_config=aiohttp_client.create_trace_config(),
url="/test-path?query=param#foobar",
status_code=200,
)

span = self.memory_exporter.get_finished_spans()[0]
self.assertEqual(
span.instrumentation_info.schema_url,
"https://opentelemetry.io/schemas/1.11.0",
)
self.memory_exporter.clear()

def test_not_recording(self):
mock_tracer = mock.Mock()
mock_span = mock.Mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,19 @@ def __init__(
meter=None,
):
self.app = guarantee_single_callable(app)
self.tracer = trace.get_tracer(__name__, __version__, tracer_provider)
self.tracer = trace.get_tracer(
__name__,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
self.meter = (
get_meter(__name__, __version__, meter_provider)
get_meter(
__name__,
__version__,
meter_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
if meter is None
else meter
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ def instrumentation_dependencies(self) -> Collection[str]:

def _instrument(self, **kwargs):
tracer_provider = kwargs.get("tracer_provider")
self._tracer = trace.get_tracer(__name__, __version__, tracer_provider)
self._tracer = trace.get_tracer(
__name__,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

for method in [
"Connection.execute",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,12 @@ def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches
except (IndexError, KeyError, TypeError):
span_kind = SpanKind.SERVER

tracer = get_tracer(__name__, __version__, tracer_provider)
tracer = get_tracer(
__name__,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

with tracer.start_as_current_span(
name=orig_handler_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ def _instrument(self, **kwargs):

# pylint: disable=attribute-defined-outside-init
self._tracer = get_tracer(
__name__, __version__, kwargs.get("tracer_provider")
__name__,
__version__,
kwargs.get("tracer_provider"),
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

wrap_function_wrapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ def _instrument(self, **kwargs: Dict[str, Any]) -> None:
"tracer_provider"
)
self._tracer: Tracer = trace.get_tracer(
__name__, __version__, self._tracer_provider
__name__,
__version__,
self._tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
self._wrap_client_creation()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def instrumentation_dependencies(self) -> Collection[str]:
def _instrument(self, **kwargs):
# pylint: disable=attribute-defined-outside-init
self._tracer = get_tracer(
__name__, __version__, kwargs.get("tracer_provider")
__name__,
__version__,
kwargs.get("tracer_provider"),
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

self.request_hook = kwargs.get("request_hook")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def _instrument(tracer_provider, include_db_statement=False):

Wraps cassandra.cluster.Session.execute_async().
"""
tracer = trace.get_tracer(__name__, __version__, tracer_provider)
tracer = trace.get_tracer(
__name__,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
name = "Cassandra"

def _traced_execute_async(func, instance, args, kwargs):
Expand All @@ -65,7 +70,10 @@ def _traced_execute_async(func, instance, args, kwargs):
if span.is_recording():
span.set_attribute(SpanAttributes.DB_NAME, instance.keyspace)
span.set_attribute(SpanAttributes.DB_SYSTEM, "cassandra")
span.set_attribute(SpanAttributes.NET_PEER_NAME, instance.cluster.contact_points)
span.set_attribute(
SpanAttributes.NET_PEER_NAME,
instance.cluster.contact_points,
)

if include_db_statement:
query = args[0]
Expand All @@ -74,7 +82,9 @@ def _traced_execute_async(func, instance, args, kwargs):
response = func(*args, **kwargs)
return response

wrap_function_wrapper("cassandra.cluster", "Session.execute_async", _traced_execute_async)
wrap_function_wrapper(
"cassandra.cluster", "Session.execute_async", _traced_execute_async
)


class CassandraInstrumentor(BaseInstrumentor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,25 @@ def tearDown(self):
def test_instrument_uninstrument(self):
instrumentation = CassandraInstrumentor()
instrumentation.instrument()
self.assertTrue(isinstance(cassandra.cluster.Session.execute_async, BoundFunctionWrapper))
self.assertTrue(
isinstance(
cassandra.cluster.Session.execute_async, BoundFunctionWrapper
)
)

instrumentation.uninstrument()
self.assertFalse(isinstance(cassandra.cluster.Session.execute_async, BoundFunctionWrapper))
self.assertFalse(
isinstance(
cassandra.cluster.Session.execute_async, BoundFunctionWrapper
)
)

@mock.patch("cassandra.cluster.Cluster.connect")
@mock.patch("cassandra.cluster.Session.__init__")
@mock.patch("cassandra.cluster.Session._create_response_future")
def test_instrumentor(self, mock_create_response_future, mock_session_init, mock_connect):
def test_instrumentor(
self, mock_create_response_future, mock_session_init, mock_connect
):
mock_create_response_future.return_value = mock.Mock()
mock_session_init.return_value = None
mock_connect.return_value = cassandra.cluster.Session()
Expand Down Expand Up @@ -85,7 +95,9 @@ def test_instrumentor(self, mock_create_response_future, mock_session_init, mock
@mock.patch("cassandra.cluster.Cluster.connect")
@mock.patch("cassandra.cluster.Session.__init__")
@mock.patch("cassandra.cluster.Session._create_response_future")
def test_custom_tracer_provider(self, mock_create_response_future, mock_session_init, mock_connect):
def test_custom_tracer_provider(
self, mock_create_response_future, mock_session_init, mock_connect
):
mock_create_response_future.return_value = mock.Mock()
mock_session_init.return_value = None
mock_connect.return_value = cassandra.cluster.Session()
Expand All @@ -107,7 +119,9 @@ def test_custom_tracer_provider(self, mock_create_response_future, mock_session_
@mock.patch("cassandra.cluster.Cluster.connect")
@mock.patch("cassandra.cluster.Session.__init__")
@mock.patch("cassandra.cluster.Session._create_response_future")
def test_instrument_connection_no_op_tracer_provider(self, mock_create_response_future, mock_session_init, mock_connect):
def test_instrument_connection_no_op_tracer_provider(
self, mock_create_response_future, mock_session_init, mock_connect
):
mock_create_response_future.return_value = mock.Mock()
mock_session_init.return_value = None
mock_connect.return_value = cassandra.cluster.Session()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,20 @@ def _instrument(self, **kwargs):
tracer_provider = kwargs.get("tracer_provider")

# pylint: disable=attribute-defined-outside-init
self._tracer = trace.get_tracer(__name__, __version__, tracer_provider)
self._tracer = trace.get_tracer(
__name__,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

meter_provider = kwargs.get("meter_provider")
meter = get_meter(__name__, __version__, meter_provider)
meter = get_meter(
__name__,
__version__,
meter_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

self.create_celery_metrics(meter)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ def instrument_producer(
producer: Producer, tracer_provider=None
) -> ProxiedProducer:
tracer = trace.get_tracer(
__name__, __version__, tracer_provider=tracer_provider
__name__,
__version__,
tracer_provider=tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

manual_producer = ProxiedProducer(producer, tracer)
Expand All @@ -241,7 +244,10 @@ def instrument_consumer(
consumer: Consumer, tracer_provider=None
) -> ProxiedConsumer:
tracer = trace.get_tracer(
__name__, __version__, tracer_provider=tracer_provider
__name__,
__version__,
tracer_provider=tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

manual_consumer = ProxiedConsumer(consumer, tracer)
Expand Down Expand Up @@ -272,7 +278,10 @@ def _instrument(self, **kwargs):

tracer_provider = kwargs.get("tracer_provider")
tracer = trace.get_tracer(
__name__, __version__, tracer_provider=tracer_provider
__name__,
__version__,
tracer_provider=tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

self._tracer = tracer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def __init__(
self._name,
instrumenting_library_version=self._version,
tracer_provider=tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
self.capture_parameters = capture_parameters
self.enable_commenter = enable_commenter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,14 @@ def _instrument(self, **kwargs):
__name__,
__version__,
tracer_provider=tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
meter = get_meter(
__name__,
__version__,
meter_provider=meter_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
meter = get_meter(__name__, __version__, meter_provider=meter_provider)
_DjangoMiddleware._tracer = tracer
_DjangoMiddleware._meter = meter
_DjangoMiddleware._excluded_urls = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ def _instrument(self, **kwargs):
Instruments Elasticsearch module
"""
tracer_provider = kwargs.get("tracer_provider")
tracer = get_tracer(__name__, __version__, tracer_provider)
tracer = get_tracer(
__name__,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
request_hook = kwargs.get("request_hook")
response_hook = kwargs.get("response_hook")
if es_transport_split:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,17 @@ def __init__(self, *args, **kwargs):
self._middlewares_list = [self._middlewares_list]

self._otel_tracer = trace.get_tracer(
__name__, __version__, tracer_provider
__name__,
__version__,
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
self._otel_meter = get_meter(
__name__,
__version__,
meter_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
self._otel_meter = get_meter(__name__, __version__, meter_provider)
self.duration_histogram = self._otel_meter.create_histogram(
name=MetricInstruments.HTTP_SERVER_DURATION,
unit="ms",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ def instrument_app(
excluded_urls = _excluded_urls_from_env
else:
excluded_urls = parse_excluded_urls(excluded_urls)
meter = get_meter(__name__, __version__, meter_provider)
meter = get_meter(
__name__,
__version__,
meter_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)

app.add_middleware(
OpenTelemetryMiddleware,
Expand Down Expand Up @@ -295,7 +300,10 @@ class _InstrumentedFastAPI(fastapi.FastAPI):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
meter = get_meter(
__name__, __version__, _InstrumentedFastAPI._meter_provider
__name__,
__version__,
_InstrumentedFastAPI._meter_provider,
schema_url="https://opentelemetry.io/schemas/1.11.0",
)
self.add_middleware(
OpenTelemetryMiddleware,
Expand Down
Loading
Loading