Skip to content

[Core] Tracing updates#39563

Merged
pvaneck merged 15 commits intoAzure:mainfrom
pvaneck:core-tracing-update
Mar 5, 2025
Merged

[Core] Tracing updates#39563
pvaneck merged 15 commits intoAzure:mainfrom
pvaneck:core-tracing-update

Conversation

@pvaneck
Copy link
Copy Markdown
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
Copy Markdown
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 <paulvaneck@microsoft.com>
@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 <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Copy link
Copy Markdown

@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

Comment thread sdk/core/azure-core/samples/example_tracing.py Outdated
Comment thread sdk/core/azure-core/samples/example_tracing.py Outdated
Comment thread sdk/core/azure-core/samples/example_tracing.py
Comment thread sdk/core/azure-core/samples/example_tracing.py
Comment thread sdk/core/azure-core/samples/example_tracing.py Outdated
Comment thread sdk/core/azure-core/azure/core/tracing/decorator.py Outdated
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Comment thread sdk/core/azure-core/CHANGELOG.md
Comment thread sdk/core/azure-core/azure/core/pipeline/policies/_distributed_tracing.py Outdated
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Copy link
Copy Markdown
Contributor

@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 🐱

Comment thread sdk/core/azure-core/CHANGELOG.md
Comment thread sdk/core/azure-core/CHANGELOG.md
Comment thread sdk/core/azure-core/CHANGELOG.md Outdated
Comment thread sdk/core/azure-core/azure/core/instrumentation.py
Comment thread sdk/core/azure-core/azure/core/tracing/_models.py Outdated
Comment thread sdk/core/azure-core/azure/core/tracing/decorator.py Outdated
Comment thread sdk/core/azure-core/azure/core/tracing/opentelemetry.py Outdated
Comment thread sdk/core/azure-core/azure/core/tracing/opentelemetry.py
Comment thread sdk/core/azure-core/CHANGELOG.md Outdated
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Copy link
Copy Markdown
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!

Comment thread sdk/core/azure-core/CHANGELOG.md
Comment thread sdk/core/azure-core/CHANGELOG.md
Comment thread sdk/core/azure-core/CHANGELOG.md Outdated
Comment thread sdk/core/azure-core/CHANGELOG.md Outdated
Comment thread sdk/core/azure-core/azure/core/instrumentation.py
Comment thread sdk/core/azure-core/azure/core/tracing/opentelemetry.py
Comment thread sdk/core/azure-core/azure/core/tracing/_models.py Outdated
Comment thread sdk/core/azure-core/azure/core/tracing/decorator.py Outdated
Comment thread sdk/core/azure-core/azure/core/pipeline/policies/_distributed_tracing.py Outdated
pvaneck added 2 commits March 4, 2025 02:23
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
@pvaneck
Copy link
Copy Markdown
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
@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 <paulvaneck@microsoft.com>
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