Skip to content

[Core] Tracing updates #39563

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

Merged
merged 15 commits into from
Mar 5, 2025
Merged

[Core] Tracing updates #39563

merged 15 commits into from
Mar 5, 2025

Conversation

pvaneck
Copy link
Member

@pvaneck pvaneck commented Feb 5, 2025

Additional context: https://gist.github.com/pvaneck/12273663942e70e71cea36bf40716d8d

This introduces native OpenTelemetry tracing to Azure Core. This is intended to be an alternative/replacement to the azure-core-tracing-opentelemetry plugin.

To enable native OpenTelemetry tracing, users need to:

  1. Have opentelemetry-api installed.
  2. Ensure that settings.tracing_implementation is not set.
  3. Ensure that settings.tracing_enabled is set to True.

If setting.tracing_implementation is set, the tracing plugin will be used instead of the native tracing. If settings.tracing_enabled is set to False, tracing will be disabled.

Main changes

  • opentelemetry-api is added as an optional dependency, and is needed to enable native tracing.
  • The OpenTelemetryTracer class was added to the azure.core.tracing.opentelemetry module. This is a wrapper around the OpenTelemetry tracer that is used to create spans for Azure SDK operations.
  • Added a get_tracer method to the new azure.core.instrumentation module. This method returns an instance of the OpenTelemetryTracer class.
  • A TracingOptions TypedDict class was added to define the options that SDK users can use to configure tracing per-operation. These options include the ability to enable or disable tracing and set additional attributes on spans.
    - Example usage: client.method(tracing_options={"enabled": True, "attributes": {"foo": "bar"}})
  • The DistributedTracingPolicy and distributed_trace/distributed_trace_async decorators now uses the OpenTelemetry tracer if it is available and native tracing is enabled.
    • SDK clients can define an _instrumentation_config class variable to configure the OpenTelemetry tracer used in method span creation. Possible configuration options are library_name, library_version, schema_url, and attributes.
    • DistributedTracingPolicy now accepts a instrumentation_config keyword argument to configure the OpenTelemetry tracer used in HTTP span creation.

@pvaneck pvaneck force-pushed the core-tracing-update branch from 4072688 to 5268fb4 Compare February 5, 2025 05:43
@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

azure-core

@pvaneck pvaneck force-pushed the core-tracing-update branch 3 times, most recently from be04837 to c81d021 Compare February 6, 2025 03:04
@pvaneck pvaneck marked this pull request as ready for review February 6, 2025 03:04
Signed-off-by: Paul Van Eck <[email protected]>
@pvaneck pvaneck force-pushed the core-tracing-update branch from c81d021 to 74e47e4 Compare February 6, 2025 03:11
Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
Copy link
Member

@lmolkova lmolkova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great - thanks a lot for putting it together!

Left some naming suggestions and other minor suggestions

Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
Copy link
Member

@kristapratico kristapratico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nits and questions 🐱

Signed-off-by: Paul Van Eck <[email protected]>
Copy link
Member Author

@pvaneck pvaneck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @kristapratico, for the feedback!

pvaneck added 2 commits March 4, 2025 02:23
Signed-off-by: Paul Van Eck <[email protected]>
Signed-off-by: Paul Van Eck <[email protected]>
@pvaneck
Copy link
Member Author

pvaneck commented Mar 5, 2025

Verified that the azure-core-tracing-opentelemetry live tests still work with these changes. Adding live tests for native tracing here: #39945

@pvaneck pvaneck merged commit ab9a180 into Azure:main Mar 5, 2025
55 checks passed
@pvaneck pvaneck deleted the core-tracing-update branch March 5, 2025 23:13
allenkim0129 pushed a commit to allenkim0129/azure-sdk-for-python that referenced this pull request Mar 11, 2025
This introduces native OpenTelemetry tracing to Azure Core. 

Signed-off-by: Paul Van Eck <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants