Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 140fc8e

Browse files
authored
Update thread sampling smoke tests (#360)
* cleanup MockTracerAgent * add support for logsCollectorPort in TestHelper * logs service proto from https://github.com/open-telemetry/opentelemetry-proto/blob/f8c59fe6b063397714034d9727f08aca1a5b99b3/opentelemetry/proto/collector/logs/v1/logs_service.proto * c# namespaces for OpenTelemetry.TestHelpers in proto files * add OpenTelemetry.TestHelper * Generate protobug classes for OpenTelemetry.TestHelpers * mocked version of OtelLogsCollector * use MockOtelLogCollectors is test * Ensure that OpenTracing.TestHelper builds before DataDog.TestHelper
1 parent 6601973 commit 140fc8e

File tree

21 files changed

+598
-18
lines changed

21 files changed

+598
-18
lines changed

Datadog.Trace.sln

+15
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.OpenTracing", "trac
460460
EndProject
461461
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.ThreadSampling", "tracer\test\test-applications\integrations\Samples.ThreadSampling\Samples.ThreadSampling.csproj", "{873C3CE9-B051-4412-9D0D-05E7D67F1A99}"
462462
EndProject
463+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.TestHelpers", "tracer\test\OpenTelemetry.TestHelpers\OpenTelemetry.TestHelpers.csproj", "{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}"
464+
EndProject
463465
Global
464466
GlobalSection(SharedMSBuildProjectFiles) = preSolution
465467
tracer\test\test-applications\Samples.Shared\Samples.Shared.projitems*{24d3e547-8897-4111-baa2-b92f50cc13d4}*SharedItemsImports = 5
@@ -2214,6 +2216,18 @@ Global
22142216
{873C3CE9-B051-4412-9D0D-05E7D67F1A99}.Release|x64.Build.0 = Release|x64
22152217
{873C3CE9-B051-4412-9D0D-05E7D67F1A99}.Release|x86.ActiveCfg = Release|x86
22162218
{873C3CE9-B051-4412-9D0D-05E7D67F1A99}.Release|x86.Build.0 = Release|x86
2219+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2220+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
2221+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Debug|x64.ActiveCfg = Debug|Any CPU
2222+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Debug|x64.Build.0 = Debug|Any CPU
2223+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Debug|x86.ActiveCfg = Debug|Any CPU
2224+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Debug|x86.Build.0 = Debug|Any CPU
2225+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
2226+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Release|Any CPU.Build.0 = Release|Any CPU
2227+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Release|x64.ActiveCfg = Release|Any CPU
2228+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Release|x64.Build.0 = Release|Any CPU
2229+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Release|x86.ActiveCfg = Release|Any CPU
2230+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2}.Release|x86.Build.0 = Release|Any CPU
22172231
EndGlobalSection
22182232
GlobalSection(SolutionProperties) = preSolution
22192233
HideSolutionNode = FALSE
@@ -2380,6 +2394,7 @@ Global
23802394
{C7EC2FF7-C495-4A35-80DF-1F57B61214AC} = {8CEC2042-F11C-49F5-A674-2355793B600A}
23812395
{EC308C70-B148-46E3-A121-D70F23CD116A} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
23822396
{873C3CE9-B051-4412-9D0D-05E7D67F1A99} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A}
2397+
{A1FCF83B-C0C0-47E1-8862-76DEC8492BA2} = {8CEC2042-F11C-49F5-A674-2355793B600A}
23832398
EndGlobalSection
23842399
GlobalSection(ExtensibilityGlobals) = postSolution
23852400
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2020, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
// NOTE: This proto is experimental and is subject to change at this point.
18+
// Please do not use it at the moment.
19+
20+
package opentelemetry.proto.collector.logs.v1;
21+
22+
import "opentelemetry/proto/logs/v1/logs.proto";
23+
24+
option java_multiple_files = true;
25+
option java_package = "io.opentelemetry.proto.collector.logs.v1";
26+
option java_outer_classname = "LogsServiceProto";
27+
option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/collector/logs/v1";
28+
option csharp_namespace = "OpenTelemetry.TestHelpers.Proto.Collector.Logs.V1";
29+
30+
// Service that can be used to push logs between one Application instrumented with
31+
// OpenTelemetry and an collector, or between an collector and a central collector (in this
32+
// case logs are sent/received to/from multiple Applications).
33+
service LogsService {
34+
// For performance reasons, it is recommended to keep this RPC
35+
// alive for the entire life of the application.
36+
rpc Export(ExportLogsServiceRequest) returns (ExportLogsServiceResponse) {}
37+
}
38+
39+
message ExportLogsServiceRequest {
40+
// An array of ResourceLogs.
41+
// For data coming from a single resource this array will typically contain one
42+
// element. Intermediary nodes (such as OpenTelemetry Collector) that receive
43+
// data from multiple origins typically batch the data before forwarding further and
44+
// in that case this array will contain multiple elements.
45+
repeated opentelemetry.proto.logs.v1.ResourceLogs resource_logs = 1;
46+
}
47+
48+
message ExportLogsServiceResponse {
49+
}

opentelemetry/proto/common/v1/common.proto

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ option java_package = "io.opentelemetry.proto.common.v1";
2121
option java_outer_classname = "CommonProto";
2222
option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/common/v1";
2323
option csharp_namespace = "Datadog.Tracer.OpenTelemetry.Proto.Common.V1";
24+
// option csharp_namespace = "OpenTelemetry.TestHelpers.Proto.Common.V1";
2425

2526
// AnyValue is used to represent any type of attribute value. AnyValue may contain a
2627
// primitive value such as a string or integer or it may contain an arbitrary nested

opentelemetry/proto/logs/v1/logs.proto

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ option java_package = "io.opentelemetry.proto.logs.v1";
2424
option java_outer_classname = "LogsProto";
2525
option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/logs/v1";
2626
option csharp_namespace = "Datadog.Tracer.OpenTelemetry.Proto.Logs.V1";
27+
// option csharp_namespace = "OpenTelemetry.TestHelpers.Proto.Logs.V1";
2728

2829
// LogsData represents the logs data that can be stored in a persistent storage,
2930
// OR can be embedded by other protocols that transfer OTLP logs data but do not

opentelemetry/proto/resource/v1/resource.proto

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ option java_package = "io.opentelemetry.proto.resource.v1";
2323
option java_outer_classname = "ResourceProto";
2424
option go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go/resource/v1";
2525
option csharp_namespace = "Datadog.Tracer.OpenTelemetry.Proto.Resource.V1";
26+
// option csharp_namespace = "OpenTelemetry.TestHelpers.Proto.Resource.V1";
2627

2728
// Resource information.
2829
message Resource {

tracer/Datadog.Trace.proj

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<RazorPagesProject Include="test/test-applications/**/Samples.AspNetCoreRazorPages.csproj" />
1515
<ExcludeExpenseItDemoProject Remove="test/test-applications/regression/**/ExpenseItDemo*.csproj" />
1616
<ExcludeLegacyRedisProject Remove="test/test-applications/regression/**/StackExchange.Redis.AssemblyConflict.LegacyProject.csproj" />
17-
<CsharpTestHelperProject Include="test\**\*.TestHelpers.csproj"/>
17+
<CsharpTestHelperProject Include="test\**\OpenTelemetry.TestHelpers.csproj;test\**\*.TestHelpers.csproj"/>
1818
<CppProject Include="src\**\*.vcxproj"/>
1919
<CppTestProject Include="test\**\*.vcxproj"/>
2020
<VbSampleLibProject Include="test\test-applications\integrations\**\*.vbproj" />

tracer/build/_build/Build.Steps.cs

+1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ void CopyWaf(string architecture, IEnumerable<string> frameworks, AbsolutePath a
596596
$"src/**/bin/{BuildConfiguration}",
597597
$"src/Datadog.Trace.Tools.Runner/obj/{BuildConfiguration}",
598598
$"test/Datadog.Trace.TestHelpers/**/bin/{BuildConfiguration}",
599+
$"test/OpenTelemetry.TestHelpers/**/bin/{BuildConfiguration}",
599600
$"test/test-applications/integrations/dependency-libs/**/bin/{BuildConfiguration}"
600601
);
601602

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/SmokeTests/SmokeTestBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected void CheckForSmoke(bool shouldDeserializeTraces = true)
7878
{
7979
// Initialize StartInfo
8080
process.StartInfo.FileName = executable;
81-
EnvironmentHelper.SetEnvironmentVariables(agent.Port, aspNetCorePort, statsdPort: null, process.StartInfo.EnvironmentVariables, processToProfile: executable);
81+
EnvironmentHelper.SetEnvironmentVariables(agent.Port, aspNetCorePort, statsdPort: null, logsCollectorPort: null, process.StartInfo.EnvironmentVariables, processToProfile: executable);
8282
if (EnvironmentHelper.IsCoreClr())
8383
{
8484
// Command becomes: dotnet.exe <applicationPath>

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/ThreadSamplingTests.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@ public void SubmitTheadSamples()
2626
SetEnvironmentVariable("SIGNALFX_THREAD_SAMPLING_ENABLED", "true");
2727
SetEnvironmentVariable("SIGNALFX_THREAD_SAMPLING_PERIOD", "1000");
2828

29-
// TODO: Start OTel collector, and capture stakcs sent to it, verify the actual stacks.
30-
// While that is not done use verbose log directed to the stdout.
31-
SetEnvironmentVariable("SIGNALFX_TRACE_DEBUG", "true");
32-
SetEnvironmentVariable("SIGNALFX_STDOUT_LOG_ENABLED", "true");
33-
3429
using (var agent = EnvironmentHelper.GetMockAgent())
35-
using (var processResult = RunSampleAndWaitForExit(agent.Port))
30+
using (var logsCollector = EnvironmentHelper.GetMockOtelLogsCollector())
31+
using (var processResult = RunSampleAndWaitForExit(agent.Port, logCollectorPort: logsCollector.Port))
3632
{
33+
var logsData = logsCollector.LogsData.ToArray();
3734
// The application works for 5 seconds with debug logging enabled we expect at least 2 attempts of thread sampling in CI.
3835
// On a dev box it is typical to get at least 3 but the CI machines seem slower, using 2 until the test is improved.
39-
processResult.StandardOutput.Should().Contain("thread samples captured at", AtLeast.Times(expected: 2));
36+
logsData.Length.Should().BeGreaterOrEqualTo(expected: 2);
4037
}
4138
}
4239
}

tracer/test/Datadog.Trace.Security.IntegrationTests/AspNetBase.cs

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private async Task StartSample(
131131
int? aspNetCorePort = null,
132132
string packageVersion = "",
133133
int? statsdPort = null,
134+
int? logsCollectorPort = null,
134135
string framework = "",
135136
string path = "/Home",
136137
bool enableSecurity = true,
@@ -159,6 +160,7 @@ private async Task StartSample(
159160
args,
160161
traceAgentPort: traceAgentPort,
161162
statsdPort: statsdPort,
163+
logsCollectorPort: logsCollectorPort,
162164
aspNetCorePort: aspNetCorePort.GetValueOrDefault(5000),
163165
enableSecurity: enableSecurity,
164166
enableBlocking: enableBlocking,

tracer/test/Datadog.Trace.TestHelpers/Datadog.Trace.TestHelpers.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
<ItemGroup>
44
<PackageReference Include="Bogus" Version="34.0.1" />
5-
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
65
<PackageReference Include="MessagePack" Version="1.9.11" />
76
<PackageReference Include="PublicApiGenerator" Version="10.2.0" />
87
</ItemGroup>
98

109
<ItemGroup>
1110
<ProjectReference Include="..\..\src\Datadog.Trace\Datadog.Trace.csproj" />
11+
<ProjectReference Include="..\OpenTelemetry.TestHelpers\OpenTelemetry.TestHelpers.csproj" />
1212
</ItemGroup>
1313

1414
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">

tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Runtime.InteropServices;
1414
using System.Runtime.Versioning;
1515
using Datadog.Trace.Configuration;
16+
using OpenTelemetry.TestHelpers;
1617
using Xunit.Abstractions;
1718

1819
namespace Datadog.Trace.TestHelpers
@@ -193,6 +194,7 @@ public void SetEnvironmentVariables(
193194
int agentPort,
194195
int aspNetCorePort,
195196
int? statsdPort,
197+
int? logsCollectorPort,
196198
StringDictionary environmentVariables,
197199
string processToProfile = null,
198200
bool enableSecurity = false,
@@ -236,6 +238,11 @@ public void SetEnvironmentVariables(
236238
environmentVariables["SIGNALFX_DOGSTATSD_PORT"] = statsdPort.Value.ToString();
237239
}
238240

241+
if (logsCollectorPort.HasValue)
242+
{
243+
environmentVariables["SIGNALFX_LOGS_ENDPOINT_URL"] = $"http://127.0.0.1:{logsCollectorPort.Value}/";
244+
}
245+
239246
if (enableSecurity)
240247
{
241248
environmentVariables[ConfigurationKeys.AppSecEnabled] = enableSecurity.ToString();
@@ -461,5 +468,15 @@ public MockTracerAgent GetMockAgent(bool useStatsD = false)
461468

462469
return agent;
463470
}
471+
472+
public MockOtelLogsCollector GetMockOtelLogsCollector()
473+
{
474+
var logsCollectorPort = TcpPortProvider.GetOpenPort();
475+
var logsCollector = new MockOtelLogsCollector(logsCollectorPort);
476+
477+
_output.WriteLine($"Assigned port {logsCollector.Port} for the logsCollectorPort.");
478+
479+
return logsCollector;
480+
}
464481
}
465482
}

tracer/test/Datadog.Trace.TestHelpers/MockTracerAgent.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Collections.Generic;
1111
using System.Collections.Immutable;
1212
using System.Collections.Specialized;
13-
using System.Diagnostics;
1413
using System.Linq;
1514
using System.Net;
1615
using System.Net.Sockets;
@@ -101,7 +100,7 @@ public MockTracerAgent(int port = 8126, int retries = 5, bool useStatsd = false)
101100

102101
/// <summary>
103102
/// Gets the TCP port that this Agent is listening on.
104-
/// Can be different from <see cref="MockTracerAgent(int, int)"/>'s <c>initialPort</c>
103+
/// Can be different from <see cref="MockTracerAgent(int, int, bool)"/>'s <c>initialPort</c>
105104
/// parameter if listening on that port fails.
106105
/// </summary>
107106
public int Port { get; }

tracer/test/Datadog.Trace.TestHelpers/ProfilerHelper.cs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static Process StartProcessWithProfiler(
1818
int traceAgentPort = 9696,
1919
int aspNetCorePort = 5000,
2020
int? statsdPort = null,
21+
int? logsCollectorPort = null,
2122
string processToProfile = null,
2223
bool? enableSecurity = null,
2324
bool? enableBlocking = null,
@@ -37,6 +38,7 @@ public static Process StartProcessWithProfiler(
3738
traceAgentPort,
3839
aspNetCorePort,
3940
statsdPort,
41+
logsCollectorPort,
4042
startInfo.EnvironmentVariables,
4143
processToProfile,
4244
enableSecurity.GetValueOrDefault(),

tracer/test/Datadog.Trace.TestHelpers/TestHelper.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected TestHelper(EnvironmentHelper environmentHelper, ITestOutputHelper outp
5757

5858
protected ITestOutputHelper Output { get; }
5959

60-
public Process StartDotnetTestSample(int traceAgentPort, string arguments, string packageVersion, int aspNetCorePort, int? statsdPort = null, string framework = "")
60+
public Process StartDotnetTestSample(int traceAgentPort, string arguments, string packageVersion, int aspNetCorePort, int? statsdPort = null, int? logsCollectorPort = null, string framework = "")
6161
{
6262
// get path to sample app that the profiler will attach to
6363
string sampleAppPath = EnvironmentHelper.GetTestCommandForSampleApplicationPath(packageVersion, framework);
@@ -78,13 +78,14 @@ public Process StartDotnetTestSample(int traceAgentPort, string arguments, strin
7878
$"{appPath} {arguments ?? string.Empty}",
7979
traceAgentPort: traceAgentPort,
8080
statsdPort: statsdPort,
81+
logsCollectorPort: logsCollectorPort,
8182
aspNetCorePort: aspNetCorePort,
8283
processToProfile: exec + ";testhost.exe");
8384
}
8485

85-
public ProcessResult RunDotnetTestSampleAndWaitForExit(int traceAgentPort, int? statsdPort = null, string arguments = null, string packageVersion = "", string framework = "")
86+
public ProcessResult RunDotnetTestSampleAndWaitForExit(int traceAgentPort, int? statsdPort = null, int? logsCollectorPort = null, string arguments = null, string packageVersion = "", string framework = "")
8687
{
87-
var process = StartDotnetTestSample(traceAgentPort, arguments, packageVersion, aspNetCorePort: 5000, statsdPort: statsdPort, framework: framework);
88+
var process = StartDotnetTestSample(traceAgentPort, arguments, packageVersion, aspNetCorePort: 5000, statsdPort: statsdPort, logsCollectorPort: logsCollectorPort, framework: framework);
8889

8990
using var helper = new ProcessHelper(process);
9091

@@ -112,7 +113,7 @@ public ProcessResult RunDotnetTestSampleAndWaitForExit(int traceAgentPort, int?
112113
return new ProcessResult(process, standardOutput, standardError, exitCode);
113114
}
114115

115-
public Process StartSample(int traceAgentPort, string arguments, string packageVersion, int aspNetCorePort, int? statsdPort = null, string framework = "")
116+
public Process StartSample(int traceAgentPort, string arguments, string packageVersion, int aspNetCorePort, int? statsdPort = null, int? logCollectorPort = null, string framework = "")
116117
{
117118
// get path to sample app that the profiler will attach to
118119
string sampleAppPath = EnvironmentHelper.GetSampleApplicationPath(packageVersion, framework);
@@ -131,13 +132,14 @@ public Process StartSample(int traceAgentPort, string arguments, string packageV
131132
args,
132133
traceAgentPort: traceAgentPort,
133134
statsdPort: statsdPort,
135+
logsCollectorPort: logCollectorPort,
134136
aspNetCorePort: aspNetCorePort,
135137
processToProfile: executable);
136138
}
137139

138-
public ProcessResult RunSampleAndWaitForExit(int traceAgentPort, int? statsdPort = null, string arguments = null, string packageVersion = "", string framework = "", int aspNetCorePort = 5000)
140+
public ProcessResult RunSampleAndWaitForExit(int traceAgentPort, int? statsdPort = null, int? logCollectorPort = null, string arguments = null, string packageVersion = "", string framework = "", int aspNetCorePort = 5000)
139141
{
140-
var process = StartSample(traceAgentPort, arguments, packageVersion, aspNetCorePort: aspNetCorePort, statsdPort: statsdPort, framework: framework);
142+
var process = StartSample(traceAgentPort, arguments, packageVersion, aspNetCorePort: aspNetCorePort, statsdPort: statsdPort, logCollectorPort: logCollectorPort, framework: framework);
141143

142144
using var helper = new ProcessHelper(process);
143145

0 commit comments

Comments
 (0)