|
2 | 2 |
|
3 | 3 | import datadog.trace.util.FNV64Hash; |
4 | 4 |
|
| 5 | +import javax.xml.crypto.Data; |
| 6 | + |
5 | 7 | public class DataStreamsTags { |
6 | 8 | public enum Direction { |
7 | 9 | Unknown, |
@@ -50,6 +52,9 @@ public enum Direction { |
50 | 52 | public static final String HAS_ROUTING_KEY_TAG = "has_routing_key"; |
51 | 53 | public static final String KAFKA_CLUSTER_ID_TAG = "kafka_cluster_id"; |
52 | 54 |
|
| 55 | + private static volatile ThreadLocal<String> serviceNameOverride; |
| 56 | + private static volatile long baseHash; |
| 57 | + |
53 | 58 | public static byte[] longToBytes(long val) { |
54 | 59 | return new byte[] { |
55 | 60 | (byte) val, |
@@ -144,6 +149,14 @@ public static DataStreamsTags createWithDataset( |
144 | 149 | null); |
145 | 150 | } |
146 | 151 |
|
| 152 | + public static void setServiceNameOverride(ThreadLocal<String> serviceNameOverride) { |
| 153 | + DataStreamsTags.serviceNameOverride = serviceNameOverride; |
| 154 | + } |
| 155 | + |
| 156 | + public static void setGlobalBaseHash(long hash) { |
| 157 | + DataStreamsTags.baseHash = hash; |
| 158 | + } |
| 159 | + |
147 | 160 | public static DataStreamsTags createWithClusterId( |
148 | 161 | String type, Direction direction, String topic, String clusterId) { |
149 | 162 | return new DataStreamsTags( |
@@ -209,6 +222,17 @@ public DataStreamsTags( |
209 | 222 | kafkaClusterId != null ? KAFKA_CLUSTER_ID_TAG + ":" + kafkaClusterId : null; |
210 | 223 | this.partition = partition != null ? PARTITION_TAG + ":" + partition : null; |
211 | 224 |
|
| 225 | + if (DataStreamsTags.baseHash != 0) { |
| 226 | + this.hash = DataStreamsTags.baseHash; |
| 227 | + } |
| 228 | + |
| 229 | + if (DataStreamsTags.serviceNameOverride != null) { |
| 230 | + String val = DataStreamsTags.serviceNameOverride.get(); |
| 231 | + if (val != null) { |
| 232 | + this.hash = FNV64Hash.continueHash(this.hash, val, FNV64Hash.Version.v1); |
| 233 | + } |
| 234 | + } |
| 235 | + |
212 | 236 | // hashable tags are 0-4 |
213 | 237 | for (int i = 0; i < 7; i++) { |
214 | 238 | String tag = this.tagByIndex(i); |
|
0 commit comments