-
Notifications
You must be signed in to change notification settings - Fork 3k
[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
[Core] Tracing updates #39563
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
74e47e4
[Core] Tracing updates
pvaneck d6d4093
Updates
pvaneck 2f8febf
Sample update
pvaneck afa01f5
Updates
pvaneck 2774f8e
black + changelog updates
pvaneck bf8cca8
Refactoring
pvaneck cec327c
Mark some imports private
pvaneck fff925c
Tracing policy refactor
pvaneck 912fbb2
updates
pvaneck f75e05f
Cleanup
pvaneck 3973a97
Add async sample
pvaneck e12d882
span exception event updates
pvaneck 4114a35
Review feedback
pvaneck 42b262b
Fix typo
pvaneck 845bd7a
add CIEnumMeta
pvaneck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,6 +353,7 @@ | |
"onmicrosoft", | ||
"openai", | ||
"OPENAI", | ||
"otel", | ||
"otlp", | ||
"OTLP", | ||
"owasp", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
from typing import Optional, Union, Mapping, TYPE_CHECKING | ||
from functools import lru_cache | ||
|
||
if TYPE_CHECKING: | ||
from .tracing.opentelemetry import OpenTelemetryTracer | ||
|
||
|
||
def _get_tracer_impl(): | ||
# Check if OpenTelemetry is available/installed. | ||
try: | ||
from .tracing.opentelemetry import OpenTelemetryTracer | ||
|
||
return OpenTelemetryTracer | ||
except ImportError: | ||
return None | ||
|
||
|
||
@lru_cache | ||
def _get_tracer_cached( | ||
library_name: Optional[str], | ||
library_version: Optional[str], | ||
schema_url: Optional[str], | ||
attributes_key: Optional[frozenset], | ||
) -> Optional["OpenTelemetryTracer"]: | ||
tracer_impl = _get_tracer_impl() | ||
if tracer_impl: | ||
# Convert attributes_key back to dict if needed | ||
attributes = dict(attributes_key) if attributes_key else None | ||
return tracer_impl( | ||
library_name=library_name, | ||
library_version=library_version, | ||
schema_url=schema_url, | ||
attributes=attributes, | ||
) | ||
return None | ||
|
||
|
||
def get_tracer( | ||
*, | ||
library_name: Optional[str] = None, | ||
library_version: Optional[str] = None, | ||
schema_url: Optional[str] = None, | ||
attributes: Optional[Mapping[str, Union[str, bool, int, float]]] = None, | ||
pvaneck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> Optional["OpenTelemetryTracer"]: | ||
"""Get the OpenTelemetry tracer instance if available. | ||
|
||
If OpenTelemetry is not available, this method will return None. This method caches | ||
the tracer instance for each unique set of parameters. | ||
|
||
:keyword library_name: The name of the library to use in the tracer. | ||
:paramtype library_name: str | ||
:keyword library_version: The version of the library to use in the tracer. | ||
:paramtype library_version: str | ||
:keyword schema_url: Specifies the Schema URL of the emitted spans. Defaults to | ||
"https://opentelemetry.io/schemas/1.23.1". | ||
:paramtype schema_url: str | ||
:keyword attributes: Attributes to add to the emitted spans. | ||
:paramtype attributes: Mapping[str, Union[str, bool, int, float]] | ||
:return: The OpenTelemetry tracer instance if available. | ||
:rtype: Optional[~azure.core.tracing.opentelemetry.OpenTelemetryTracer] | ||
""" | ||
attributes_key = frozenset(attributes.items()) if attributes else None | ||
return _get_tracer_cached(library_name, library_version, schema_url, attributes_key) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.