-
Notifications
You must be signed in to change notification settings - Fork 9
Add span links #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add span links #229
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2a3dced
add span links
nikhilc-microsoft 73c8856
address pr comments
nikhilc-microsoft 7bc103d
Merge branch 'main' into nikhilc/supportSpanLinks
nikhilNava d95b356
Update src/Observability/Runtime/Tracing/Contracts/SpanDetails.cs
nikhilNava 178228a
Merge branch 'main' into nikhilc/supportSpanLinks
nikhilNava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
src/Tests/Microsoft.Agents.A365.Observability.Runtime.Tests/Tracing/Scopes/SpanLinksTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.Agents.A365.Observability.Tests.Tracing.Scopes; | ||
|
|
||
| using System.Diagnostics; | ||
| using FluentAssertions; | ||
| using Microsoft.Agents.A365.Observability.Runtime.Tracing.Contracts; | ||
| using Microsoft.Agents.A365.Observability.Runtime.Tracing.Scopes; | ||
|
|
||
| [TestClass] | ||
| public sealed class SpanLinksTest : ActivityTest | ||
| { | ||
| private static readonly ActivityLink[] SampleLinks = new[] | ||
| { | ||
| new ActivityLink( | ||
| new ActivityContext( | ||
| ActivityTraceId.CreateFromString("0aa4621e5ae09963a3de354f3d18aa65"), | ||
| ActivitySpanId.CreateFromString("c1aaa519600b1bf0"), | ||
| ActivityTraceFlags.Recorded)), | ||
| new ActivityLink( | ||
| new ActivityContext( | ||
| ActivityTraceId.CreateFromString("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), | ||
| ActivitySpanId.CreateFromString("aaaaaaaaaaaaaaaa"), | ||
| ActivityTraceFlags.None), | ||
| new ActivityTagsCollection(new[] { new KeyValuePair<string, object?>("link.reason", "retry") })), | ||
| }; | ||
|
|
||
| [TestMethod] | ||
| public void ExecuteToolScope_RecordsSpanLinks_WithFullContextAndAttributes() | ||
| { | ||
| var activity = ListenForActivity(() => | ||
| { | ||
| using var scope = ExecuteToolScope.Start( | ||
| Util.GetDefaultRequest(), | ||
| new ToolCallDetails("my-tool", "args"), | ||
| Util.GetAgentDetails(), | ||
| spanDetails: new SpanDetails(spanLinks: SampleLinks)); | ||
| }); | ||
|
|
||
| var links = activity.Links.ToList(); | ||
| links.Should().HaveCount(2); | ||
| links[0].Context.TraceId.ToHexString().Should().Be("0aa4621e5ae09963a3de354f3d18aa65"); | ||
| links[0].Context.SpanId.ToHexString().Should().Be("c1aaa519600b1bf0"); | ||
| links[0].Context.TraceFlags.Should().Be(ActivityTraceFlags.Recorded); | ||
| links[1].Context.TraceId.ToHexString().Should().Be("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); | ||
| links[1].Context.SpanId.ToHexString().Should().Be("aaaaaaaaaaaaaaaa"); | ||
| links[1].Tags.Should().Contain(new KeyValuePair<string, object?>("link.reason", "retry")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ExecuteToolScope_HasEmptyLinks_WhenSpanLinksOmitted() | ||
| { | ||
| var activity = ListenForActivity(() => | ||
| { | ||
| using var scope = ExecuteToolScope.Start( | ||
| Util.GetDefaultRequest(), | ||
| new ToolCallDetails("my-tool", "args"), | ||
| Util.GetAgentDetails()); | ||
| }); | ||
|
|
||
| activity.Links.Should().BeEmpty(); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void InvokeAgentScope_ForwardsSpanLinks() | ||
| { | ||
| var activity = ListenForActivity(() => | ||
| { | ||
| using var scope = InvokeAgentScope.Start( | ||
| Util.GetDefaultRequest(), | ||
| ScopeDetails, | ||
| TestAgentDetails, | ||
| spanDetails: new SpanDetails(spanLinks: SampleLinks)); | ||
| }); | ||
|
|
||
| var links = activity.Links.ToList(); | ||
| links.Should().HaveCount(2); | ||
| links[0].Context.TraceId.ToHexString().Should().Be("0aa4621e5ae09963a3de354f3d18aa65"); | ||
| links[0].Context.SpanId.ToHexString().Should().Be("c1aaa519600b1bf0"); | ||
| links[0].Context.TraceFlags.Should().Be(ActivityTraceFlags.Recorded); | ||
| links[1].Context.TraceId.ToHexString().Should().Be("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); | ||
| links[1].Context.SpanId.ToHexString().Should().Be("aaaaaaaaaaaaaaaa"); | ||
| links[1].Context.TraceFlags.Should().Be(ActivityTraceFlags.None); | ||
| links[1].Tags.Should().Contain(new KeyValuePair<string, object?>("link.reason", "retry")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void InferenceScope_ForwardsSpanLinks() | ||
| { | ||
| var details = new InferenceCallDetails( | ||
| InferenceOperationType.Chat, "gpt-4", "openai"); | ||
|
|
||
| var activity = ListenForActivity(() => | ||
| { | ||
| using var scope = InferenceScope.Start( | ||
| Util.GetDefaultRequest(), | ||
| details, | ||
| Util.GetAgentDetails(), | ||
| spanDetails: new SpanDetails(spanLinks: SampleLinks)); | ||
| }); | ||
|
|
||
| var links = activity.Links.ToList(); | ||
| links.Should().HaveCount(2); | ||
| links[0].Context.TraceId.ToHexString().Should().Be("0aa4621e5ae09963a3de354f3d18aa65"); | ||
| links[0].Context.SpanId.ToHexString().Should().Be("c1aaa519600b1bf0"); | ||
| } | ||
nikhilNava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [TestMethod] | ||
| public void OutputScope_ForwardsSpanLinks() | ||
| { | ||
| var response = new Response(new[] { "hello" }); | ||
|
|
||
| var activity = ListenForActivity(() => | ||
| { | ||
| using var scope = OutputScope.Start( | ||
| Util.GetDefaultRequest(), | ||
| response, | ||
| Util.GetAgentDetails(), | ||
| spanDetails: new SpanDetails(spanLinks: SampleLinks)); | ||
| }); | ||
|
|
||
| var links = activity.Links.ToList(); | ||
| links.Should().HaveCount(2); | ||
| links[0].Context.TraceId.ToHexString().Should().Be("0aa4621e5ae09963a3de354f3d18aa65"); | ||
| links[0].Context.SpanId.ToHexString().Should().Be("c1aaa519600b1bf0"); | ||
| } | ||
nikhilNava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [TestMethod] | ||
| public void SpanLinks_PreservesTypedAttributes() | ||
| { | ||
| var linksWithAttrs = new[] | ||
| { | ||
| new ActivityLink( | ||
| new ActivityContext( | ||
| ActivityTraceId.CreateFromString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), | ||
| ActivitySpanId.CreateFromString("bbbbbbbbbbbbbbbb"), | ||
| ActivityTraceFlags.Recorded), | ||
| new ActivityTagsCollection(new[] | ||
| { | ||
| new KeyValuePair<string, object?>("link.type", "causal"), | ||
| new KeyValuePair<string, object?>("link.index", 0), | ||
| })), | ||
| }; | ||
|
|
||
| var activity = ListenForActivity(() => | ||
| { | ||
| using var scope = InvokeAgentScope.Start( | ||
| Util.GetDefaultRequest(), | ||
| ScopeDetails, | ||
| new AgentDetails("attr-agent"), | ||
| spanDetails: new SpanDetails(spanLinks: linksWithAttrs)); | ||
| }); | ||
|
|
||
| var links = activity.Links.ToList(); | ||
| links.Should().HaveCount(1); | ||
| links[0].Tags.Should().Contain(new KeyValuePair<string, object?>("link.type", "causal")); | ||
| links[0].Tags.Should().Contain(new KeyValuePair<string, object?>("link.index", 0)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.