-
Notifications
You must be signed in to change notification settings - Fork 780
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
Adding resource tags dinamically after initialization #1470
Comments
@tiagonapoli , depending on what kind of instrumentation you are using, you could private static void ActivityEnrichment(Activity activity, string method, object obj)
{
switch (method)
{
case "OnStartActivity":
var resource = activity.GetResource();
resource.Merge(new Resources.Resource(new Dictionary<string, object>()));
activity.SetResource(resource);
break;
case "OnStopActivity":
Assert.True(obj is HttpResponse);
break;
default:
break;
}
} |
Currently we're using AspNetCore and Http auto instrumentations. About the enrich solution, we would have to merge the resource for every activity created, do you think the overhead would be considerable? Does caching the merged resource would be better? public static class GlobalResource {
// this initially is set with some tags
// once data is fetched from AWS this is replaced with a new resource with all data
public static Resource Data;
} private static void ActivityEnrichment(Activity activity, string method, object obj)
{
switch (method)
{
case "OnStartActivity":
activity.SetResource(GlobalResource.Data);
break;
case "OnStopActivity":
// is this necessary?
Assert.True(obj is HttpResponse);
break;
default:
break;
}
} Also, the enrichment would work for Activities created using a |
For the caching strategy, yes, that would help with the allocation since we would only need to allocate the new Resource once. For the enrichment part, it will affect performance when you use I thought I did commit the benchmark for that. I will create a new PR adding it. But you can look here: #1261 (comment) For the processor question, yes that should work as well. |
Awesome! Thanks a lot! |
As per the current spec for Resource, resource is associated with a TracerProvider/MeterProvider, and is same for all the traces/metrics from that provider, and cannot be changed after provider creation. |
Closing this issue as no pending items here. |
Question
First of all, congratulations on the awesome work!
On OpenTelemetry initialization we do something similar to the following:
However, to fetch host and cloud information we have to block the initialization process to make calls to AWS API. We would prefer not to block initialization because of this.
Is there a way to add tags to the resource after initialization? Do you guys think of an alternative solution?
The text was updated successfully, but these errors were encountered: