public static Scope CreateDbCommandScope(Tracer tracer, IDbCommand command, string integrationName) { if (!tracer.Settings.IsIntegrationEnabled(integrationName)) { // integration disabled, don't create a scope, skip this trace return(null); } Scope scope = null; try { string dbType = GetDbType(command.GetType().Name); if (dbType == null) { // don't create a scope, skip this trace return(null); } Span parent = tracer.ActiveScope?.Span; if (parent != null && parent.Type == SpanTypes.Sql && parent.GetTag(Tags.DbType) == dbType && parent.ResourceName == command.CommandText) { // we are already instrumenting this, // don't instrument nested methods that belong to the same stacktrace // e.g. ExecuteReader() -> ExecuteReader(commandBehavior) return(null); } string serviceName = $"{tracer.DefaultServiceName}-{dbType}"; string operationName = $"{dbType}.query"; var tags = new SqlTags(); scope = tracer.StartActiveWithTags(operationName, tags: tags, serviceName: serviceName); var span = scope.Span; tags.DbType = dbType; tags.InstrumentationName = integrationName; span.AddTagsFromDbCommand(command); // set analytics sample rate if enabled var analyticsSampleRate = tracer.Settings.GetIntegrationAnalyticsSampleRate(integrationName, enabledWithGlobalSetting: false); if (analyticsSampleRate != null) { tags.AnalyticsSampleRate = analyticsSampleRate; } } catch (Exception ex) { Log.Error(ex, "Error creating or populating scope."); } return(scope); }
private static Scope CreateDbCommandScope(Tracer tracer, IDbCommand command, IntegrationId integrationId, string dbType, string operationName, string serviceName, ref DbCommandCache.TagsCacheItem tagsFromConnectionString) { if (!tracer.Settings.IsIntegrationEnabled(integrationId) || !tracer.Settings.IsIntegrationEnabled(IntegrationId.AdoNet)) { // integration disabled, don't create a scope, skip this span return(null); } Scope scope = null; try { Span parent = tracer.InternalActiveScope?.Span; if (IsDbAlreadyInstrumented(parent, dbType, command.CommandText)) { // we are already instrumenting this, // don't instrument nested methods that belong to the same stacktrace // e.g. ExecuteReader() -> ExecuteReader(commandBehavior) return(null); } var tags = new SqlTags { DbType = dbType, InstrumentationName = IntegrationRegistry.GetName(integrationId) }; tags.SetAnalyticsSampleRate(integrationId, tracer.Settings, enabledWithGlobalSetting: false); scope = tracer.StartActiveInternal(operationName, tags: tags, serviceName: serviceName); scope.Span.AddTagsFromDbCommand(command); tracer.TracerManager.Telemetry.IntegrationGeneratedSpan(integrationId); } catch (Exception ex) { Log.Error(ex, "Error creating or populating scope."); } return(scope); }
private static Scope CreateDbCommandScope(Tracer tracer, IDbCommand command, IntegrationId integrationId, string dbType, string operationName, string serviceName, ref DbCommandCache.TagsCacheItem tagsFromConnectionString) { if (!tracer.Settings.IsIntegrationEnabled(integrationId) || !tracer.Settings.IsIntegrationEnabled(IntegrationId.AdoNet)) { // integration disabled, don't create a scope, skip this span return(null); } Scope scope = null; try { Span parent = tracer.InternalActiveScope?.Span; if (parent is { Type : SpanTypes.Sql } && parent.GetTag(Tags.DbType) == dbType && parent.ResourceName == command.CommandText) { // we are already instrumenting this, // don't instrument nested methods that belong to the same stacktrace // e.g. ExecuteReader() -> ExecuteReader(commandBehavior) return(null); } var tags = new SqlTags { DbType = dbType, InstrumentationName = IntegrationRegistry.GetName(integrationId), DbName = tagsFromConnectionString.DbName, DbUser = tagsFromConnectionString.DbUser, OutHost = tagsFromConnectionString.OutHost, }; tags.SetAnalyticsSampleRate(integrationId, tracer.Settings, enabledWithGlobalSetting: false); scope = tracer.StartActiveInternal(operationName, tags: tags, serviceName: serviceName); scope.Span.ResourceName = command.CommandText; scope.Span.Type = SpanTypes.Sql; tracer.TracerManager.Telemetry.IntegrationGeneratedSpan(integrationId); }
public static Scope CreateDbCommandScope(Tracer tracer, IDbCommand command) { if (!tracer.Settings.IsIntegrationEnabled(AdoNetConstants.IntegrationId)) { // integration disabled, don't create a scope, skip this trace return(null); } var commandType = command.GetType(); if (tracer.Settings.AdoNetExcludedTypes.Count > 0 && tracer.Settings.AdoNetExcludedTypes.Contains(commandType.FullName)) { // AdoNet type disabled, don't create a scope, skip this trace return(null); } Scope scope = null; try { string dbType = GetDbType(commandType.Namespace, commandType.Name); if (dbType == null) { // don't create a scope, skip this trace return(null); } Span parent = tracer.ActiveScope?.Span; if (parent != null && parent.Type == SpanTypes.Sql && parent.GetTag(Tags.DbType) == dbType && parent.ResourceName == command.CommandText) { // we are already instrumenting this, // don't instrument nested methods that belong to the same stacktrace // e.g. ExecuteReader() -> ExecuteReader(commandBehavior) return(null); } string serviceName = tracer.Settings.GetServiceName(tracer, dbType); string operationName = $"{dbType}.query"; var tags = new SqlTags(); scope = tracer.StartActiveWithTags(operationName, tags: tags, serviceName: serviceName); var span = scope.Span; tags.DbType = dbType; span.AddTagsFromDbCommand(command); tags.SetAnalyticsSampleRate(AdoNetConstants.IntegrationId, tracer.Settings, enabledWithGlobalSetting: false); } catch (Exception ex) { Log.Error(ex, "Error creating or populating scope."); } return(scope); }
public static Scope CreateDbCommandScope(Tracer tracer, IDbCommand command) { if (command.GetType() != _type) { // if the type of the instance is different than the factory type // (if the method instrumented is defined in a base class) // we fallback to the previous factory. return(ScopeFactory.CreateDbCommandScope(tracer, command)); } if (_dbTypeName == null) { // don't create a scope, skip this span return(null); } if (!tracer.Settings.IsIntegrationEnabled(AdoNetConstants.IntegrationId)) { // integration disabled, don't create a scope, skip this span return(null); } if (tracer.Settings.AdoNetExcludedTypes.Count > 0 && tracer.Settings.AdoNetExcludedTypes.Contains(_fullName)) { // AdoNet type disabled, don't create a scope, skip this span return(null); } Scope scope = null; try { Span parent = tracer.ActiveScope?.Span; if (parent != null && parent.Type == SpanTypes.Sql && parent.GetTag(Tags.DbType) == _dbTypeName && parent.ResourceName == command.CommandText) { // we are already instrumenting this, // don't instrument nested methods that belong to the same stacktrace // e.g. ExecuteReader() -> ExecuteReader(commandBehavior) return(null); } string serviceName = tracer.Settings.GetServiceName(tracer, _dbTypeName); var tags = new SqlTags(); scope = tracer.StartActiveWithTags(_operationName, tags: tags, serviceName: serviceName); scope.Span.AddTagsFromDbCommand(command); tags.DbType = _dbTypeName; tags.SetAnalyticsSampleRate(AdoNetConstants.IntegrationId, tracer.Settings, enabledWithGlobalSetting: false); } catch (Exception ex) { Log.Error(ex, "Error creating or populating scope."); } return(scope); }