Skip to content

Commit 203fd70

Browse files
committed
Simplify tags creation
1 parent 7710a2b commit 203fd70

3 files changed

Lines changed: 24 additions & 99 deletions

File tree

tracer/src/Datadog.Trace/Configuration/Schema/ClientSchema.cs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ internal sealed class ClientSchema
1515
{
1616
private const string HttpClientComponent = "http-client";
1717
private const string GrpcClientComponent = "grpc-client";
18-
private readonly SchemaVersion _version;
19-
private readonly bool _peerServiceTagsEnabled;
18+
private readonly bool _useV0Tags;
2019
private readonly string[] _protocols;
2120
private readonly string[] _serviceNames;
2221
private readonly string _operationNameSuffix;
2322

2423
public ClientSchema(SchemaVersion version, bool peerServiceTagsEnabled, bool removeClientServiceNamesEnabled, string defaultServiceName, IReadOnlyDictionary<string, string>? serviceNameMappings)
2524
{
26-
_version = version;
27-
_peerServiceTagsEnabled = peerServiceTagsEnabled;
25+
_useV0Tags = version == SchemaVersion.V0 && !peerServiceTagsEnabled;
2826
_protocols = version switch
2927
{
3028
SchemaVersion.V0 => V0Values.ProtocolOperationNames,
@@ -79,39 +77,19 @@ public enum Component
7977
public string GetServiceName(Component component) => _serviceNames[(int)component];
8078

8179
public HttpTags CreateHttpTags()
82-
=> _version switch
83-
{
84-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new HttpTags(),
85-
_ => new HttpV1Tags(),
86-
};
80+
=> _useV0Tags ? new HttpTags() : new HttpV1Tags();
8781

8882
public GrpcClientTags CreateGrpcClientTags()
89-
=> _version switch
90-
{
91-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new GrpcClientTags(),
92-
_ => new GrpcClientV1Tags(),
93-
};
83+
=> _useV0Tags ? new GrpcClientTags() : new GrpcClientV1Tags();
9484

9585
public RemotingClientTags CreateRemotingClientTags()
96-
=> _version switch
97-
{
98-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new RemotingClientTags(),
99-
_ => new RemotingClientV1Tags(),
100-
};
86+
=> _useV0Tags ? new RemotingClientTags() : new RemotingClientV1Tags();
10187

10288
public ServiceRemotingClientTags CreateServiceRemotingClientTags()
103-
=> _version switch
104-
{
105-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new ServiceRemotingClientTags(),
106-
_ => new ServiceRemotingClientV1Tags(),
107-
};
89+
=> _useV0Tags ? new ServiceRemotingClientTags() : new ServiceRemotingClientV1Tags();
10890

10991
public AzureServiceBusTags CreateAzureServiceBusTags()
110-
=> _version switch
111-
{
112-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new AzureServiceBusTags(),
113-
_ => new AzureServiceBusV1Tags(),
114-
};
92+
=> _useV0Tags ? new AzureServiceBusTags() : new AzureServiceBusV1Tags();
11593

11694
private static class V0Values
11795
{

tracer/src/Datadog.Trace/Configuration/Schema/DatabaseSchema.cs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ internal sealed class DatabaseSchema
2424
"mongodb.query",
2525
];
2626

27-
private readonly SchemaVersion _version;
28-
private readonly bool _peerServiceTagsEnabled;
27+
private readonly bool _useV0Tags;
2928
private readonly string[] _serviceNames;
3029

3130
public DatabaseSchema(SchemaVersion version, bool peerServiceTagsEnabled, bool removeClientServiceNamesEnabled, string defaultServiceName, IReadOnlyDictionary<string, string>? serviceNameMappings)
3231
{
33-
_version = version;
34-
_peerServiceTagsEnabled = peerServiceTagsEnabled;
32+
_useV0Tags = version == SchemaVersion.V0 && !peerServiceTagsEnabled;
3533

3634
// Calculate service names once, to avoid allocations with every call
3735
var useSuffix = version == SchemaVersion.V0 && !removeClientServiceNamesEnabled;
@@ -96,54 +94,26 @@ public enum OperationType
9694
public string GetServiceName(ServiceType databaseType) => _serviceNames[(int)databaseType];
9795

9896
public CouchbaseTags CreateCouchbaseTags()
99-
=> _version switch
100-
{
101-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new CouchbaseTags(),
102-
_ => new CouchbaseV1Tags(),
103-
};
97+
=> _useV0Tags ? new CouchbaseTags() : new CouchbaseV1Tags();
10498

10599
public ElasticsearchTags CreateElasticsearchTags()
106-
=> _version switch
107-
{
108-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new ElasticsearchTags(),
109-
_ => new ElasticsearchV1Tags(),
110-
};
100+
=> _useV0Tags ? new ElasticsearchTags() : new ElasticsearchV1Tags();
111101

112102
public MongoDbTags CreateMongoDbTags()
113-
=> _version switch
114-
{
115-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new MongoDbTags(),
116-
_ => new MongoDbV1Tags(),
117-
};
103+
=> _useV0Tags ? new MongoDbTags() : new MongoDbV1Tags();
118104

119105
public SqlTags CreateSqlTags()
120-
=> _version switch
121-
{
122-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new SqlTags(),
123-
_ => new SqlV1Tags(),
124-
};
106+
=> _useV0Tags ? new SqlTags() : new SqlV1Tags();
125107

126108
public RedisTags CreateRedisTags()
127-
=> _version switch
128-
{
129-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new RedisTags(),
130-
_ => new RedisV1Tags(),
131-
};
109+
=> _useV0Tags ? new RedisTags() : new RedisV1Tags();
132110

133111
public CosmosDbTags CreateCosmosDbTags()
134-
=> _version switch
135-
{
136-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new CosmosDbTags(),
137-
_ => new CosmosDbV1Tags(),
138-
};
112+
=> _useV0Tags ? new CosmosDbTags() : new CosmosDbV1Tags();
139113

140114
public AerospikeTags CreateAerospikeTags()
141-
=> _version switch
142-
{
143-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new AerospikeTags(),
144-
_ => new AerospikeV1Tags(),
145-
};
115+
=> _useV0Tags ? new AerospikeTags() : new AerospikeV1Tags();
146116

147-
public AwsDynamoDbTags CreateAwsDynamoDbTags() => new AwsDynamoDbTags();
117+
public AwsDynamoDbTags CreateAwsDynamoDbTags() => new();
148118
}
149119
}

tracer/src/Datadog.Trace/Configuration/Schema/MessagingSchema.cs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ namespace Datadog.Trace.Configuration.Schema
1212
{
1313
internal sealed class MessagingSchema
1414
{
15-
private readonly SchemaVersion _version;
16-
private readonly bool _peerServiceTagsEnabled;
15+
private readonly bool _useV0Tags;
1716
private readonly string[] _inboundOperationNames;
1817
private readonly string[] _outboundOperationNames;
1918
private readonly string[] _serviceNames;
2019

2120
public MessagingSchema(SchemaVersion version, bool peerServiceTagsEnabled, bool removeClientServiceNamesEnabled, string defaultServiceName, IReadOnlyDictionary<string, string>? serviceNameMappings)
2221
{
23-
_version = version;
24-
_peerServiceTagsEnabled = peerServiceTagsEnabled;
25-
22+
_useV0Tags = version == SchemaVersion.V0 && !peerServiceTagsEnabled;
2623
_inboundOperationNames = version switch
2724
{
2825
SchemaVersion.V0 => V0Values.InboundOperationNames,
@@ -117,20 +114,12 @@ public enum ServiceType
117114
public string GetServiceName(ServiceType messagingSystem) => _serviceNames[(int)messagingSystem];
118115

119116
public KafkaTags CreateKafkaTags(string spanKind)
120-
=> _version switch
121-
{
122-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new KafkaTags(spanKind),
123-
_ => new KafkaV1Tags(spanKind),
124-
};
117+
=> _useV0Tags ? new KafkaTags(spanKind) : new KafkaV1Tags(spanKind);
125118

126119
public IbmMqTags CreateIbmMqTags(string spanKind) => new(spanKind);
127120

128121
public MsmqTags CreateMsmqTags(string spanKind)
129-
=> _version switch
130-
{
131-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new MsmqTags(spanKind),
132-
_ => new MsmqV1Tags(spanKind),
133-
};
122+
=> _useV0Tags ? new MsmqTags(spanKind) : new MsmqV1Tags(spanKind);
134123

135124
public AwsS3Tags CreateAwsS3Tags(string spanKind) => new AwsS3Tags(spanKind);
136125

@@ -145,30 +134,18 @@ public MsmqTags CreateMsmqTags(string spanKind)
145134
public AwsStepFunctionsTags CreateAwsStepFunctionsTags(string spanKind) => new AwsStepFunctionsTags(spanKind);
146135

147136
public RabbitMQTags CreateRabbitMqTags(string spanKind)
148-
=> _version switch
149-
{
150-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new RabbitMQTags(spanKind),
151-
_ => new RabbitMQV1Tags(spanKind),
152-
};
137+
=> _useV0Tags ? new RabbitMQTags(spanKind) : new RabbitMQV1Tags(spanKind);
153138

154139
public AzureServiceBusTags CreateAzureServiceBusTags(string spanKind)
155140
{
156-
var tags = _version switch
157-
{
158-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new AzureServiceBusTags(),
159-
_ => new AzureServiceBusV1Tags(),
160-
};
141+
var tags = _useV0Tags ? new AzureServiceBusTags() : new AzureServiceBusV1Tags();
161142
tags.SpanKind = spanKind;
162143
return tags;
163144
}
164145

165146
public AzureEventHubsTags CreateAzureEventHubsTags(string spanKind)
166147
{
167-
var tags = _version switch
168-
{
169-
SchemaVersion.V0 when !_peerServiceTagsEnabled => new AzureEventHubsTags(spanKind),
170-
_ => new AzureEventHubsV1Tags(spanKind),
171-
};
148+
var tags = _useV0Tags ? new AzureEventHubsTags(spanKind) : new AzureEventHubsV1Tags(spanKind);
172149
return tags;
173150
}
174151

0 commit comments

Comments
 (0)