-
Notifications
You must be signed in to change notification settings - Fork 5k
[API Proposal]: System.ClientModel Open Telemetry extension APIs #114084
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
Comments
The |
@teo-tsirpanis MarkFailed follows the OTel spec for recording errors https://opentelemetry.io/docs/specs/semconv/general/recording-errors/ by setting the span status and description, as well as setting error.type to a predictable value based on typical errors seen in clients built on System.ClientModel (with fallbacks if it's not typical). Makes it super easy for client library authors to instrument their client methods. |
Thanks. In this case it might be better to define |
@teo-tsirpanis I think setting the status and description is universal, but the error.type attribute would need to be customizable since the value is potentially defined differently by every instrumentation. This is the draft implementation: public static Activity MarkFailed(this Activity activity, Exception? exception)
{
activity.SetStatus(ActivityStatusCode.Error, exception?.Message);
string? errorCode = null;
if (exception is ClientResultException clientResultException) // ClientResultException is a System.ClientModel exception type
{
errorCode = clientResultException.Status.ToString();
}
errorCode ??= exception?.GetType().FullName;
errorCode ??= "_OTHER";
activity.SetTag("error.type", errorCode);
return activity;
} The activity.SetStatus is something that applies everywhere, but everything else is specific to System.ClientModel. I'm definitely not opposed to adding the method to System.Diagnostics instead, but the method wouldn't be able to do much more than just the SetStatus line, so it doesn't seem as helpful for users in the general case. |
@tarekgh, @samsp-msft, @noahfalk. This is proposing additional Activity{Source} APIs (albeit as extension methods) |
Regarding MarkFailed, Activity already has AddException API. I am not sure if this is worth extension API either as it is simple setting the error and adding the exception. But I wouldn't mind having it as an extension method there if it is important. |
Regrarding |
idk if you saw my reply about that one above - #114084 (comment)
Benefits of having it are:
No, we don't in SCM. There are a few Azure SDKs that start Activities with links, so I added the parameter for consistency, but I'm fine with simplifying this method if it's not very common. |
I am fine with the proposal. |
Background and motivation
The System.ClientModel library provides building blocks for .NET clients that call cloud services. For background, this package has been reviewed in the following previous issues: #94126 | #97711 | #104617 | #106197 | #111046
These additional APIs are adding extension methods for client library authors to add distributed tracing to their libraries built on System.ClientModel. Client libraries have the following spans:
The proposed API is simply adding extension methods to Activity and ActivitySource for library authors to use to create distributed tracing spans in each public method call. These methods provide common base functionality that is applicable to all client libraries. Library authors can then use the returned Activity directly to add any additional functionality to meet their own needs.
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: