-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomSdkTests.cs
95 lines (77 loc) · 2.85 KB
/
CustomSdkTests.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET
using Google.Protobuf;
using IntegrationTests.Helpers;
using OpenTelemetry.Proto.Trace.V1;
using Xunit.Abstractions;
namespace IntegrationTests;
[Collection(RedisCollection.Name)]
public class CustomSdkTests : TestHelper
{
private readonly RedisFixture _redis;
public CustomSdkTests(ITestOutputHelper output, RedisFixture redis)
: base("CustomSdk", output)
{
_redis = redis;
}
[Fact]
[Trait("Category", "EndToEnd")]
[Trait("Containers", "Linux")]
public void SubmitsTraces()
{
using var collector = new MockSpansCollector(Output);
SetExporter(collector);
// ensure spans are exported by custom sdk with custom resource
collector.ResourceExpector.Expect("test_attr", "added_manually");
collector.Expect("OpenTelemetry.Instrumentation.StackExchangeRedis", span => !IsTopLevel(span));
collector.Expect("System.Net.Http", span => !IsTopLevel(span));
collector.Expect("TestApplication.CustomSdk", span => IsTopLevel(span));
collector.Expect("NServiceBus.Core", span => IsTopLevel(span));
EnableBytecodeInstrumentation();
SetEnvironmentVariable("OTEL_DOTNET_AUTO_SETUP_SDK", "false");
SetEnvironmentVariable("OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf");
RunTestApplication(new()
{
Arguments = $"--redis {_redis.Port}"
});
collector.AssertExpectations();
collector.ResourceExpector.AssertExpectations();
}
[Fact]
[Trait("Category", "EndToEnd")]
[Trait("Containers", "Linux")]
public void SubmitsMetrics()
{
using var collector = new MockMetricsCollector(Output);
SetExporter(collector);
// ensure metrics are exported by custom sdk with custom resource
collector.ResourceExpector.Expect("test_attr", "added_manually");
collector.Expect("OpenTelemetry.Instrumentation.Http");
collector.Expect("NServiceBus.Core.Pipeline.Incoming");
collector.Expect("TestApplication.CustomSdk");
EnableBytecodeInstrumentation();
SetEnvironmentVariable("OTEL_DOTNET_AUTO_SETUP_SDK", "false");
SetEnvironmentVariable("OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf");
SetEnvironmentVariable("LONG_RUNNING", "true");
SetEnvironmentVariable("OTEL_METRIC_EXPORT_INTERVAL", "100");
var process = StartTestApplication(new()
{
Arguments = $"--redis {_redis.Port}"
});
try
{
collector.AssertExpectations();
collector.ResourceExpector.AssertExpectations();
}
finally
{
process?.Kill();
}
}
private static bool IsTopLevel(Span span)
{
return span.ParentSpanId == ByteString.Empty;
}
}
#endif