-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Azure AI Client: agent tracing prototype #38016
base: dargilco/azure-ai-client
Are you sure you want to change the base?
Azure AI Client: agent tracing prototype #38016
Conversation
""" | ||
... | ||
|
||
def set_error(self, error_code: Optional[str] = None, exc: Optional[Exception] = None) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, undo - the __exit__(exc info)
is enough for now
""" | ||
Add attribute (key value pair) to the current span. | ||
|
||
:param key: The key of the key value pair | ||
:type key: str | ||
:param value: The value of the key value pair | ||
:type value: Union[str, int] | ||
:type value: Union[str, int, float] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: need to add string[]
for inference tracing
|
||
parsed_url = urllib.parse.urlparse(http_request.url) | ||
authority = f"{parsed_url.hostname}:{parsed_url.port}" | ||
return f"{http_request.method} {authority}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: this is technically a breaking change, but also an important bugfix
also, can we cache parsed url and not re-parse it over and over again?
for token in self._context_tokens: | ||
context.detach(token) | ||
self._context_tokens.remove(token) | ||
|
||
if self.previous_context: | ||
context.attach(self.previous_context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without this the suppression flag never disappears after making a call in that context.
@@ -228,7 +230,8 @@ def kind(self, value: SpanKind) -> None: | |||
def __enter__(self) -> "OpenTelemetrySpan": | |||
# Start the span. | |||
if not isinstance(self.span_instance, NonRecordingSpan): | |||
if self.kind == SpanKind.INTERNAL: | |||
if self.kind == SpanKind.INTERNAL or self.kind == SpanKind.CLIENT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gen ai spans are client, need to suppress stuff under them too
|
||
thread = ai_client.agents.create_thread() | ||
print(f"Created thread, thread ID: {thread.id}") | ||
with tracer.start_as_current_span(scenario): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: add tracing-specific examples - this is temporary, just to see how tracing works in different scenarios
|
||
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) | ||
_params = kwargs.pop("params", {}) or {} | ||
with start_create_thread_span(self._config.project_name, messages=messages) as span: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is where monkey-patching comes really handy - helps to avoid customizing autogenerated code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is needed to avoid circular import:
(operations/_patch.py -> models -> tracing helpers -> models)
maybe there is a better way and then the contents could be moved to _agent_instr.py. Or all the problem goes away with monkey-patching
self.ended = True | ||
set_end_run(self.span, self.last_run) | ||
|
||
if self.last_run.last_error: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if it's updated with local errors, need to test failure cases
|
||
from azure.ai.client._instrumentation._utils import * # pylint: disable=unused-wildcard-import | ||
from azure.ai.client.models import _models | ||
from azure.ai.client.models._enums import MessageRole, RunStepStatus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to import
private modules?
Description
Please add an informative description that covers that changes made by the pull request and link all relevant issues.
If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines