Skip to content

Commit 66ad39d

Browse files
added ParentId to TelemetrySpan (#2740)
1 parent 1ff1155 commit 66ad39d

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

src/OpenTelemetry.Api/.publicApi/net461/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ static OpenTelemetry.Context.RuntimeContext.GetValue(string slotName) -> object
2323
static OpenTelemetry.Context.RuntimeContext.GetValue<T>(string slotName) -> T
2424
static OpenTelemetry.Context.RuntimeContext.SetValue(string slotName, object value) -> void
2525
static OpenTelemetry.Context.RuntimeContext.SetValue<T>(string slotName, T value) -> void
26+
OpenTelemetry.Trace.TelemetrySpan.ParentSpanId.get -> System.Diagnostics.ActivitySpanId

src/OpenTelemetry.Api/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ OpenTelemetry.Metrics.MeterProviderBuilder.MeterProviderBuilder() -> void
1616
static OpenTelemetry.Context.RuntimeContext.GetValue(string slotName) -> object
1717
static OpenTelemetry.Context.RuntimeContext.GetValue<T>(string slotName) -> T
1818
static OpenTelemetry.Context.RuntimeContext.SetValue(string slotName, object value) -> void
19-
static OpenTelemetry.Context.RuntimeContext.SetValue<T>(string slotName, T value) -> void
19+
static OpenTelemetry.Context.RuntimeContext.SetValue<T>(string slotName, T value) -> void
20+
OpenTelemetry.Trace.TelemetrySpan.ParentSpanId.get -> System.Diagnostics.ActivitySpanId

src/OpenTelemetry.Api/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
* Added `ParentSpanId` to `TelemetrySpan` ([#2740](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2740))
6+
57
## 1.2.0-rc1
68

79
Released 2021-Nov-29

src/OpenTelemetry.Api/Trace/TelemetrySpan.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ public bool IsRecording
6464
}
6565
}
6666

67+
/// <summary>
68+
/// Gets the identity of the parent span id, if any.
69+
/// </summary>
70+
public ActivitySpanId ParentSpanId
71+
{
72+
get
73+
{
74+
if (this.Activity == null)
75+
{
76+
return default;
77+
}
78+
else
79+
{
80+
return this.Activity.ParentSpanId;
81+
}
82+
}
83+
}
84+
6785
/// <summary>
6886
/// Sets the status of the span execution.
6987
/// </summary>

test/OpenTelemetry.Tests/Trace/TelemetrySpanTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,21 @@ public void CheckRecordExceptionEmpty()
6767
telemetrySpan.RecordException(null);
6868
Assert.Empty(activity.Events);
6969
}
70+
71+
[Fact]
72+
public void ParentIds()
73+
{
74+
using var parentActivity = new Activity("parentOperation");
75+
parentActivity.Start(); // can't generate the Id until the operation is started
76+
using var parentSpan = new TelemetrySpan(parentActivity);
77+
78+
// ParentId should be unset
79+
Assert.Equal(default, parentSpan.ParentSpanId);
80+
81+
using var childActivity = new Activity("childOperation").SetParentId(parentActivity.Id);
82+
using var childSpan = new TelemetrySpan(childActivity);
83+
84+
Assert.Equal(parentSpan.Context.SpanId, childSpan.ParentSpanId);
85+
}
7086
}
7187
}

0 commit comments

Comments
 (0)