-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for DSM manual instrumentation API (#5419)
* add integration test for manual API * change callback return type to array in extractWithDSM * remove scrubber Co-authored-by: Andrew Lock <andrew.lock@datadoghq.com> * remove indexers name Co-authored-by: Andrew Lock <andrew.lock@datadoghq.com> * clean csproj Co-authored-by: Andrew Lock <andrew.lock@datadoghq.com> * Revert "change callback return type to array in extractWithDSM" This reverts commit fdeae27. * handle pathways that are not in string arrays * remove telemetry setup from test * add timeout to sample app * rewrite sample program in a less modern way to please older versions * remove more modern stuff * bump timeout --------- Co-authored-by: Andrew Lock <andrew.lock@datadoghq.com>
- Loading branch information
1 parent
0b03553
commit fe100b0
Showing
8 changed files
with
250 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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
47 changes: 47 additions & 0 deletions
47
tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/DataStreamsMonitoringManualApiTest.cs
This file contains 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,47 @@ | ||
// <copyright file="DataStreamsMonitoringManualApiTest.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> | ||
|
||
using System.Threading.Tasks; | ||
using Datadog.Trace.Configuration; | ||
using Datadog.Trace.TestHelpers; | ||
using Datadog.Trace.TestHelpers.DataStreamsMonitoring; | ||
using FluentAssertions; | ||
using VerifyXunit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Datadog.Trace.ClrProfiler.IntegrationTests; | ||
|
||
[UsesVerify] | ||
public class DataStreamsMonitoringManualApiTest : TestHelper | ||
{ | ||
public DataStreamsMonitoringManualApiTest(ITestOutputHelper output) | ||
: base("DataStreams.ManualAPI", output) | ||
{ | ||
SetServiceVersion("1.0.0"); | ||
} | ||
|
||
[SkippableFact] | ||
[Trait("Category", "EndToEnd")] | ||
public async Task ContextPropagation() | ||
{ | ||
SetEnvironmentVariable(ConfigurationKeys.DataStreamsMonitoring.Enabled, "1"); | ||
|
||
using var agent = EnvironmentHelper.GetMockAgent(); | ||
using var processResult = await RunSampleAndWaitForExit(agent); | ||
|
||
var spans = agent.WaitForSpans(count: 2); | ||
spans.Should().HaveCount(expected: 2); | ||
spans[1].TraceId.Should().Be(spans[0].TraceId); // trace context propagation | ||
|
||
var dsPoints = agent.WaitForDataStreamsPoints(statsCount: 2); | ||
// using span verifier to add all the default scrubbers | ||
var settings = VerifyHelper.GetSpanVerifierSettings(); | ||
settings.AddDataStreamsScrubber(); | ||
await Verifier.Verify(MockDataStreamsPayload.Normalize(dsPoints), settings) | ||
.UseFileName($"{nameof(DataStreamsMonitoringManualApiTest)}.{nameof(ContextPropagation)}") | ||
.DisableRequireUniquePrefix(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
tracer/test/snapshots/DataStreamsMonitoringManualApiTest.ContextPropagation.verified.txt
This file contains 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,70 @@ | ||
{ | ||
Env: integration_tests, | ||
Service: Samples.DataStreams.ManualAPI, | ||
TracerVersion: <snip>, | ||
Lang: dotnet, | ||
Stats: [ | ||
{ | ||
Start: 1661520120000000000, | ||
Duration: 10000000000, | ||
Stats: [ | ||
{ | ||
EdgeTags: [ | ||
direction:out, | ||
topic:_queue, | ||
type:ConcurrentQueue | ||
], | ||
Hash: 4846659945844582174, | ||
PathwayLatency: /w==, | ||
EdgeLatency: /w==, | ||
PayloadSize: /w==, | ||
TimestampType: current | ||
}, | ||
{ | ||
EdgeTags: [ | ||
direction:in, | ||
topic:_queue, | ||
type:ConcurrentQueue | ||
], | ||
Hash: 11038489780599490290, | ||
ParentHash: 4846659945844582174, | ||
PathwayLatency: /w==, | ||
EdgeLatency: /w==, | ||
PayloadSize: /w==, | ||
TimestampType: current | ||
} | ||
] | ||
}, | ||
{ | ||
Start: 1661520120000000000, | ||
Duration: 10000000000, | ||
Stats: [ | ||
{ | ||
EdgeTags: [ | ||
direction:out, | ||
topic:_queue, | ||
type:ConcurrentQueue | ||
], | ||
Hash: 4846659945844582174, | ||
PathwayLatency: /w==, | ||
EdgeLatency: /w==, | ||
PayloadSize: /w==, | ||
TimestampType: origin | ||
}, | ||
{ | ||
EdgeTags: [ | ||
direction:in, | ||
topic:_queue, | ||
type:ConcurrentQueue | ||
], | ||
Hash: 11038489780599490290, | ||
ParentHash: 4846659945844582174, | ||
PathwayLatency: /w==, | ||
EdgeLatency: /w==, | ||
PayloadSize: /w==, | ||
TimestampType: origin | ||
} | ||
] | ||
} | ||
] | ||
} |
83 changes: 83 additions & 0 deletions
83
tracer/test/test-applications/integrations/Samples.DataStreams.ManualAPI/Program.cs
This file contains 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,83 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Datadog.Trace; | ||
|
||
namespace Samples.DataStreams.ManualAPI; | ||
|
||
public class Program | ||
{ | ||
private static ConcurrentQueue<string> _queue = new(); | ||
|
||
private static async Task Main(string[] args) | ||
{ | ||
var writing = Send("my message"); | ||
var reading = Receive(); | ||
|
||
// wait up to 20 second for threads | ||
await Task.WhenAny(Task.WhenAll(reading, writing), Task.Delay(TimeSpan.FromSeconds(value: 20))); | ||
} | ||
|
||
private static async Task Send(string message) | ||
{ | ||
using var scope = Tracer.Instance.StartActive("Samples.DataStreams.ManualAPI.Send"); | ||
|
||
await Task.Delay(millisecondsDelay: 100); | ||
|
||
Console.WriteLine("Sending one message to the queue..."); | ||
var sb = new StringBuilder(); | ||
var injector = new SpanContextInjector(); | ||
injector.InjectIncludingDsm(sb, (b, k, v) => b.Append($"{k}:{v};"), scope.Span.Context, "ConcurrentQueue", nameof(_queue)); | ||
sb.Append(message); | ||
_queue.Enqueue(sb.ToString()); | ||
Console.WriteLine("message sent"); | ||
} | ||
|
||
private static async Task<string> Receive() | ||
{ | ||
Console.WriteLine("Receiving one message from the queue..."); | ||
string result; | ||
while (!_queue.TryDequeue(out result)) | ||
{ | ||
await Task.Delay(millisecondsDelay: 100); | ||
Console.WriteLine("Retrying to receive"); | ||
} | ||
|
||
var headers = Parse(result, out var content); | ||
Console.WriteLine($"Parsed {headers.Count} headers"); | ||
var extractor = new SpanContextExtractor(); | ||
var extractedContext = extractor.ExtractIncludingDsm( | ||
headers, | ||
// complicated getter because we need to return an empty array if no result | ||
(d, k) => | ||
{ | ||
if (d.TryGetValue(k, out var val)) | ||
{ | ||
return [val]; | ||
} | ||
return []; | ||
}, | ||
"ConcurrentQueue", | ||
nameof(_queue)); | ||
using var scope = Tracer.Instance.StartActive("Samples.DataStreams.ManualAPI.Receive", new SpanCreationSettings { Parent = extractedContext }); | ||
|
||
Console.WriteLine("Done"); | ||
return content; | ||
} | ||
|
||
/// <returns>headers and message</returns> | ||
private static Dictionary<string, string> Parse(string raw, out string msg) | ||
{ | ||
var content = raw.Split(separator: ';'); | ||
var headers = content | ||
.Take(content.Length - 1) // SkipLast() is unavailable in older versions that we are testing on | ||
.Select(s => s.Split(separator: ':')) | ||
.ToDictionary(a => a[0], a => a[1]); | ||
msg = content.Last(); | ||
return headers; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...st-applications/integrations/Samples.DataStreams.ManualAPI/Properties/launchSettings.json
This file contains 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,23 @@ | ||
{ | ||
"profiles": { | ||
"Samples.DataStreams.ManualAPI": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"COR_ENABLE_PROFILING": "1", | ||
"COR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}", | ||
"COR_PROFILER_PATH": "$(SolutionDir)shared\\bin\\monitoring-home\\win-$(Platform)\\Datadog.Trace.ClrProfiler.Native.dll", | ||
|
||
"CORECLR_ENABLE_PROFILING": "1", | ||
"CORECLR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}", | ||
"CORECLR_PROFILER_PATH": "$(SolutionDir)shared\\bin\\monitoring-home\\win-$(Platform)\\Datadog.Trace.ClrProfiler.Native.dll", | ||
|
||
"DD_DOTNET_TRACER_HOME": "$(SolutionDir)shared\\bin\\monitoring-home", | ||
"DD_VERSION": "1.0.0", | ||
|
||
"DD_DATA_STREAMS_ENABLED": "1" | ||
}, | ||
|
||
"nativeDebugging": false | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...lications/integrations/Samples.DataStreams.ManualAPI/Samples.DataStreams.ManualAPI.csproj
This file contains 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,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\src\Datadog.Trace.Manual\Datadog.Trace.Manual.csproj" /> | ||
</ItemGroup> | ||
</Project> |