-
Notifications
You must be signed in to change notification settings - Fork 159
Add _dd.svc_src meta tag to track service name source #8274
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
Changes from all commits
b4a3c6f
3372b1b
62d49bb
657cb29
497234e
56ebf74
3e6ad51
64e79bb
d211a08
4430850
73fc174
80bb38e
2cda005
3c442ec
174a706
7fcac64
a4e0dfa
e9d7ea5
de9cb9e
2bb81e7
ebe603c
c423d2b
d14a7a2
1451a12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| using System.Threading; | ||
| using Datadog.Trace.AppSec; | ||
| using Datadog.Trace.Configuration; | ||
| using Datadog.Trace.Configuration.Schema; | ||
| using Datadog.Trace.DatabaseMonitoring; | ||
| using Datadog.Trace.Logging; | ||
| using Datadog.Trace.Tagging; | ||
|
|
@@ -24,7 +25,7 @@ internal static class DbScopeFactory | |
| private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(DbScopeFactory)); | ||
| private static bool _dbCommandCachingLogged = false; | ||
|
|
||
| private static Scope? CreateDbCommandScope(Tracer tracer, IDbCommand command, IntegrationId integrationId, string dbType, string operationName, string serviceName, ref DbCommandCache.TagsCacheItem tagsFromConnectionString) | ||
| private static Scope? CreateDbCommandScope(Tracer tracer, IDbCommand command, IntegrationId integrationId, string dbType, string operationName, string serviceName, string? serviceNameSource, ref DbCommandCache.TagsCacheItem tagsFromConnectionString) | ||
| { | ||
| var perTraceSettings = tracer.CurrentTraceSettings; | ||
| if (!perTraceSettings.Settings.IsIntegrationEnabled(integrationId) || !perTraceSettings.Settings.IsIntegrationEnabled(IntegrationId.AdoNet)) | ||
|
|
@@ -64,7 +65,7 @@ internal static class DbScopeFactory | |
| tags.SetAnalyticsSampleRate(integrationId, perTraceSettings.Settings, enabledWithGlobalSetting: false); | ||
| perTraceSettings.Schema.RemapPeerService(tags); | ||
|
|
||
| scope = tracer.StartActiveInternal(operationName, tags: tags, serviceName: serviceName); | ||
| scope = tracer.StartActiveInternal(operationName, tags: tags, serviceName: serviceName, serviceNameSource: serviceNameSource); | ||
| scope.Span.ResourceName = commandText; | ||
| scope.Span.Type = SpanTypes.Sql; | ||
| tracer.TracerManager.Telemetry.IntegrationGeneratedSpan(integrationId); | ||
|
|
@@ -236,7 +237,7 @@ public static class Cache<TCommand> | |
| private static readonly IntegrationId IntegrationId; | ||
|
|
||
| // ServiceName cache | ||
| private static KeyValuePair<string, string> _serviceNameCache; | ||
| private static KeyValuePair<string, ServiceNameMetadata> _serviceNameCache; | ||
|
|
||
| // ConnectionString tags cache | ||
| private static KeyValuePair<string, DbCommandCache.TagsCacheItem> _tagsByConnectionStringCache; | ||
|
|
@@ -264,13 +265,15 @@ static Cache() | |
| // use the cached values if command.GetType() == typeof(TCommand) | ||
| // and we successfully called TryGetIntegrationDetails() in the ctor | ||
| var tagsFromConnectionString = GetTagsFromConnectionString(command); | ||
| var (cachedServiceName, cachedServiceNameSource) = GetServiceNameMetadata(tracer, DbTypeName); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :chef-kiss: |
||
| return DbScopeFactory.CreateDbCommandScope( | ||
| tracer: tracer, | ||
| command: command, | ||
| integrationId: IntegrationId, | ||
| dbType: DbTypeName, | ||
| operationName: OperationName, | ||
| serviceName: GetServiceName(tracer, DbTypeName), | ||
| serviceName: cachedServiceName, | ||
| serviceNameSource: cachedServiceNameSource, | ||
| tagsFromConnectionString: ref tagsFromConnectionString); | ||
| } | ||
|
|
||
|
|
@@ -280,47 +283,51 @@ static Cache() | |
| { | ||
| var operationName = $"{dbTypeName}.query"; | ||
| var tagsFromConnectionString = GetTagsFromConnectionString(command); | ||
| var (resolvedServiceName, resolvedServiceNameSource) = GetServiceNameMetadata(tracer, dbTypeName); | ||
| return DbScopeFactory.CreateDbCommandScope( | ||
| tracer: tracer, | ||
| command: command, | ||
| integrationId: integrationId.Value, | ||
| dbType: dbTypeName, | ||
| operationName: operationName, | ||
| serviceName: GetServiceName(tracer, dbTypeName), | ||
| serviceName: resolvedServiceName, | ||
| serviceNameSource: resolvedServiceNameSource, | ||
| tagsFromConnectionString: ref tagsFromConnectionString); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| private static string GetServiceName(Tracer tracer, string dbTypeName) | ||
| private static ServiceNameMetadata GetServiceNameMetadata(Tracer tracer, string dbTypeName) | ||
| { | ||
| if (!tracer.CurrentTraceSettings.ServiceNames.TryGetValue(dbTypeName, out var serviceName)) | ||
| if (tracer.CurrentTraceSettings.ServiceNames.TryGetValue(dbTypeName, out var serviceName)) | ||
| { | ||
| if (DbTypeName != dbTypeName) | ||
| { | ||
| // We cannot cache in the base class | ||
| return tracer.CurrentTraceSettings.GetServiceName(dbTypeName); | ||
| } | ||
| return new ServiceNameMetadata(serviceName, ServiceNameMetadata.OptServiceMapping); | ||
| } | ||
|
|
||
| var serviceNameCache = _serviceNameCache; | ||
| if (DbTypeName != dbTypeName) | ||
| { | ||
| // We cannot cache in the base class | ||
| return tracer.CurrentTraceSettings.GetServiceNameMetadata(dbTypeName); | ||
| } | ||
|
|
||
| // If not a base class | ||
| if (serviceNameCache.Key == tracer.DefaultServiceName) | ||
| { | ||
| // Service has not changed | ||
| // Fastpath | ||
| return serviceNameCache.Value; | ||
| } | ||
| var serviceNameCache = _serviceNameCache; | ||
|
|
||
| // We create or replace the cache with the new service name | ||
| // Slowpath | ||
| var defaultServiceName = tracer.DefaultServiceName; | ||
| serviceName = tracer.CurrentTraceSettings.GetServiceName(dbTypeName); | ||
| _serviceNameCache = new KeyValuePair<string, string>(defaultServiceName, serviceName); | ||
| // If not a base class | ||
| if (serviceNameCache.Key == tracer.DefaultServiceName) | ||
| { | ||
| // Service has not changed | ||
| // Fastpath | ||
| return serviceNameCache.Value; | ||
| } | ||
|
|
||
| return serviceName; | ||
| // We create or replace the cache with the new service name | ||
| // Slowpath | ||
| var defaultServiceName = tracer.DefaultServiceName; | ||
| var metadata = tracer.CurrentTraceSettings.GetServiceNameMetadata(dbTypeName); | ||
| _serviceNameCache = new KeyValuePair<string, ServiceNameMetadata>(defaultServiceName, metadata); | ||
|
|
||
| return metadata; | ||
| } | ||
|
|
||
| private static DbCommandCache.TagsCacheItem GetTagsFromConnectionString(IDbCommand command) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,10 +34,10 @@ public static Scope CreateScope<TTarget>(Tracer tracer, TTarget target) | |
|
|
||
| try | ||
| { | ||
| var serviceName = perTraceSettings.Schema.Database.GetServiceName(DatabaseSchema.ServiceType.Aerospike); | ||
| var (serviceName, serviceNameSource) = perTraceSettings.Schema.Database.GetServiceNameMetadata(DatabaseSchema.ServiceType.Aerospike); | ||
| var tags = perTraceSettings.Schema.Database.CreateAerospikeTags(); | ||
|
|
||
| scope = tracer.StartActiveInternal(OperationName, tags: tags, serviceName: serviceName); | ||
| scope = tracer.StartActiveInternal(OperationName, tags: tags, serviceName: serviceName, serviceNameSource: serviceNameSource); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder, should we just have an overload of |
||
| var span = scope.Span; | ||
|
|
||
| if (target.TryDuckCast<HasKey>(out var hasKey)) | ||
|
|
||
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.
Good catch on this one 👍