-
Notifications
You must be signed in to change notification settings - Fork 792
/
Copy pathLink.cs
73 lines (61 loc) · 2.29 KB
/
Link.cs
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
using System.Diagnostics;
namespace OpenTelemetry.Trace;
/// <summary>
/// Link associated with the span.
/// </summary>
public readonly struct Link : IEquatable<Link>
{
internal readonly ActivityLink ActivityLink;
/// <summary>
/// Initializes a new instance of the <see cref="Link"/> struct.
/// </summary>
/// <param name="spanContext">Span context of a linked span.</param>
public Link(in SpanContext spanContext)
: this(in spanContext, attributes: null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Link"/> struct.
/// </summary>
/// <param name="spanContext">Span context of a linked span.</param>
/// <param name="attributes">Link attributes.</param>
public Link(in SpanContext spanContext, SpanAttributes? attributes)
{
this.ActivityLink = new ActivityLink(spanContext.ActivityContext, attributes?.Attributes);
}
/// <summary>
/// Gets the span context of a linked span.
/// </summary>
public SpanContext Context
=> new(this.ActivityLink.Context);
/// <summary>
/// Gets the collection of attributes associated with the link.
/// </summary>
public IEnumerable<KeyValuePair<string, object?>>? Attributes
=> this.ActivityLink.Tags;
/// <summary>
/// Compare two <see cref="Link"/> for equality.
/// </summary>
/// <param name="link1">First link to compare.</param>
/// <param name="link2">Second link to compare.</param>
public static bool operator ==(Link link1, Link link2)
=> link1.Equals(link2);
/// <summary>
/// Compare two <see cref="Link"/> for not equality.
/// </summary>
/// <param name="link1">First link to compare.</param>
/// <param name="link2">Second link to compare.</param>
public static bool operator !=(Link link1, Link link2)
=> !link1.Equals(link2);
/// <inheritdoc />
public override bool Equals(object? obj)
=> obj is Link link && this.ActivityLink.Equals(link.ActivityLink);
/// <inheritdoc />
public override int GetHashCode()
=> this.ActivityLink.GetHashCode();
/// <inheritdoc/>
public bool Equals(Link other)
=> this.ActivityLink.Equals(other.ActivityLink);
}