-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathActivityKey.cs
More file actions
50 lines (40 loc) · 1.56 KB
/
ActivityKey.cs
File metadata and controls
50 lines (40 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// <copyright file="ActivityKey.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
#nullable enable
using System;
using System.Collections.Generic;
namespace Datadog.Trace.Activity.Handlers;
internal readonly struct ActivityKey : IEquatable<ActivityKey>
{
private readonly string _traceId;
private readonly string _spanId;
public ActivityKey(string traceId, string spanId)
{
_traceId = traceId;
_spanId = spanId;
}
public ActivityKey(string id)
{
// Arbitrary which way around these are
_spanId = id;
_traceId = string.Empty;
}
public bool IsValid() => _traceId is not null && _spanId is not null;
public bool Equals(ActivityKey other) =>
string.Equals(_traceId, other._traceId, StringComparison.Ordinal) &&
string.Equals(_spanId, other._spanId, StringComparison.Ordinal);
public override bool Equals(object? obj) =>
obj is ActivityKey other && Equals(other);
public override int GetHashCode()
{
// TraceId and SpanId must be non-null, so can just just the values directly.
// If we allow this to be called with any null values, then we must add null checks here
unchecked
{
return (StringComparer.Ordinal.GetHashCode(_traceId) * 397)
^ StringComparer.Ordinal.GetHashCode(_spanId);
}
}
}