Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

fix: telemetry activity source should use its own version #207

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pkgs/telemetry/src/TracingHook.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Immutable;
using System.Diagnostics;
using LaunchDarkly.Sdk.Internal;
using System.Reflection;
using LaunchDarkly.Sdk.Server.Hooks;

namespace LaunchDarkly.Sdk.Server.Telemetry
Expand Down Expand Up @@ -72,11 +72,13 @@ public TracingHook Build()
public class TracingHook : Hook
{

private static readonly AssemblyName AssemblyName = typeof(TracingHook).GetTypeInfo().Assembly.GetName();

/// <summary>
/// Used to create new activities if the TracingHook is configured to create them.
/// Used as the source of activities if the TracingHook is configured to create them.
/// </summary>
private static readonly ActivitySource Source = new ActivitySource("LaunchDarkly.ServerSdk",
AssemblyVersions.GetAssemblyVersionForType(typeof(LdClient)).ToString());
private static readonly ActivitySource Source = new ActivitySource(AssemblyName.Name,
AssemblyName.Version.ToString());

/// <summary>
/// Returns the name of the ActivitySource that the TracingHook uses to generate Activities.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
single framework that we are testing; this allows us to test with older SDK
versions that would error out if they saw any newer target frameworks listed
here, even if we weren't running those. -->
<TestFramework Condition="'$(TESTFRAMEWORK)' == ''">netstandard2.0;net462;net6.0</TestFramework>
<TestFramework Condition="'$(TESTFRAMEWORK)' == ''">net462;net6.0</TestFramework>
<TargetFrameworks>$(TESTFRAMEWORK)</TargetFrameworks>
<AssemblyName>LaunchDarkly.ServerSdk.Telemetry.Tests</AssemblyName>
<PackageId>LaunchDarkly.ServerSdk.Telemetry.Tests</PackageId>
Expand All @@ -20,25 +20,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="OpenTelemetry" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Exporter.InMemory" Version="1.7.0" />
</ItemGroup>

<ItemGroup>
<None Update="TestFiles\all-properties.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFiles\all-properties.yml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFiles\bad-file.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFiles\flag-only.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFiles\segment-only.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void TracingHookCreatesRootSpans(bool createSpans)
{
ICollection<Activity> exportedItems = new Collection<Activity>();

var tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
_ = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
.AddSource(TracingHook.ActivitySourceName)
.AddInMemoryExporter(exportedItems)
.Build();
Expand Down Expand Up @@ -102,7 +102,7 @@ public void TracingHookCreatesChildSpans(bool createSpans)

var testSource = new ActivitySource("test-source", "1.0.0");

var tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
_ = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
.AddSource("test-source")
.AddSource(TracingHook.ActivitySourceName)
.SetResourceBuilder(
Expand Down Expand Up @@ -157,16 +157,16 @@ public void TracingHookIncludesVariant(bool includeVariant)
{
ICollection<Activity> exportedItems = new Collection<Activity>();

var testSource = new ActivitySource("test-source", "1.0.0");

var tracerProvider = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
_ = OpenTelemetry.Sdk.CreateTracerProviderBuilder()
.AddSource("test-source")
.SetResourceBuilder(
ResourceBuilder.CreateDefault()
.AddService(serviceName: "test-source", serviceVersion: "1.0.0"))
.AddInMemoryExporter(exportedItems)
.Build();

var testSource = new ActivitySource("test-source", "1.0.0");

var hookUnderTest = TracingHook.Builder().IncludeVariant(includeVariant).Build();
var featureKey = "feature-key";
var context = Context.New("foo");
Expand Down