Skip to content

Commit

Permalink
Merge branch 'main' into issue/AWS-Lambda-SQS-SNS-support
Browse files Browse the repository at this point in the history
  • Loading branch information
rypdal committed Apr 13, 2023
2 parents d2613c4 + 8e996b0 commit 70acd21
Show file tree
Hide file tree
Showing 16 changed files with 364 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-core-cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Merging test results
run: reportgenerator -reports:TestResults/**/*.xml -targetdir:TestResults -reporttypes:Cobertura

- uses: codecov/codecov-action@v3.1.1
- uses: codecov/codecov-action@v3.1.2
with:
file: TestResults/Cobertura.xml
env_vars: OS
Expand Down
18 changes: 18 additions & 0 deletions examples/enrichment/Examples.Enrichment/Examples.Enrichment.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="$(OpenTelemetryCoreLatestVersion)" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="$(OpenTelemetryCoreLatestVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry.Extensions.Enrichment\OpenTelemetry.Extensions.Enrichment.csproj" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions examples/enrichment/Examples.Enrichment/IMyService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <copyright file="IMyService.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

namespace Examples.Enrichment;

public interface IMyService
{
public (string Service, string Status) MyDailyStatus();
}
40 changes: 40 additions & 0 deletions examples/enrichment/Examples.Enrichment/MyService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// <copyright file="MyService.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;

namespace Examples.Enrichment;

internal sealed class MyService : IMyService
{
private readonly List<string> statuses = new()
{
"Blocked",
"No blockers",
"Out of office",
};

/// <summary>
/// Returns daily status.
/// </summary>
/// <returns>A tuple with service name and status.</returns>
public (string Service, string Status) MyDailyStatus()
{
var statusNumber = Random.Shared.Next(0, this.statuses.Count);
return new(nameof(MyService), this.statuses[statusNumber]);
}
}
36 changes: 36 additions & 0 deletions examples/enrichment/Examples.Enrichment/MyTraceEnricher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// <copyright file="MyTraceEnricher.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using OpenTelemetry.Extensions.Enrichment;

namespace Examples.Enrichment;

internal sealed class MyTraceEnricher : TraceEnricher
{
private readonly IMyService myService;

public MyTraceEnricher(IMyService myService)
{
this.myService = myService;
}

public override void Enrich(in TraceEnrichmentBag bag)
{
var (service, status) = this.myService.MyDailyStatus();

bag.Add(service, status);
}
}
54 changes: 54 additions & 0 deletions examples/enrichment/Examples.Enrichment/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// <copyright file="Program.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry;
using OpenTelemetry.Extensions.Enrichment;
using OpenTelemetry.Trace;

namespace Examples.Enrichment;

public static class Program
{
public static void Main()
{
// Create an ActivitySource.
using var myActivitySource = new ActivitySource("MyCompany.MyProduct.MyLibrary");

using var tracerProvider = Sdk.CreateTracerProviderBuilder()

// Register MyService in the DI container.
.ConfigureServices(services => services.AddSingleton<IMyService, MyService>())

// Register the ActivitySource as usual.
.AddSource("MyCompany.MyProduct.MyLibrary")

// Register an enricher class.
// Important: AddTraceEnricher() must be called before any exporeters.
.AddTraceEnricher<MyTraceEnricher>()

// Add Console exporter to see the output of this example.
.AddConsoleExporter()
.Build();

// Create an Activity and add some tags to it.
using var activity = myActivitySource.StartActivity("SayHello");
activity?.SetTag("hello", "world");

// Tags from the enricher class will be added automatically to the created Activity.
}
}
10 changes: 10 additions & 0 deletions opentelemetry-dotnet-contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Sampler.AWS.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Exporter.OneCollector.Benchmarks", "test\OpenTelemetry.Exporter.OneCollector.Benchmarks\OpenTelemetry.Exporter.OneCollector.Benchmarks.csproj", "{C42868C8-968A-473F-AC39-AC97C5D47E84}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples.Enrichment", "examples\enrichment\Examples.Enrichment\Examples.Enrichment.csproj", "{9B7F7605-ADFF-4A47-9B64-FFF3E2EC9DEA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "enrichment", "enrichment", "{93503FAF-D43D-48C0-818C-92EB90F7606B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -569,6 +573,10 @@ Global
{C42868C8-968A-473F-AC39-AC97C5D47E84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C42868C8-968A-473F-AC39-AC97C5D47E84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C42868C8-968A-473F-AC39-AC97C5D47E84}.Release|Any CPU.Build.0 = Release|Any CPU
{9B7F7605-ADFF-4A47-9B64-FFF3E2EC9DEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B7F7605-ADFF-4A47-9B64-FFF3E2EC9DEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B7F7605-ADFF-4A47-9B64-FFF3E2EC9DEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B7F7605-ADFF-4A47-9B64-FFF3E2EC9DEA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -657,6 +665,8 @@ Global
{54002B08-F6AE-4B2B-AB0C-86E5A05926A3} = {22DF5DC0-1290-4E83-A9D8-6BB7DE3B3E63}
{48C29501-3FA2-46A7-B5BA-D282EA8F1274} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
{C42868C8-968A-473F-AC39-AC97C5D47E84} = {2097345F-4DD3-477D-BC54-A922F9B2B402}
{9B7F7605-ADFF-4A47-9B64-FFF3E2EC9DEA} = {93503FAF-D43D-48C0-818C-92EB90F7606B}
{93503FAF-D43D-48C0-818C-92EB90F7606B} = {B75EE478-97F7-4E9F-9A5A-DB3D0988EDEA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B0816796-CDB3-47D7-8C3C-946434DE3B66}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>.Enrich(T enrichmentBag) -> void
abstract OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>.Enrich(in T enrichmentBag) -> void
Microsoft.Extensions.DependencyInjection.OpenTelemetryEnrichmentServiceCollectionExtensions
OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>
OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>.BaseEnricher() -> void
Expand All @@ -17,4 +17,3 @@ static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilde
static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilderExtensions.AddTraceEnricher(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action<OpenTelemetry.Extensions.Enrichment.TraceEnrichmentBag>! enrichmentAction) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilderExtensions.AddTraceEnricher(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Func<System.IServiceProvider!, OpenTelemetry.Extensions.Enrichment.TraceEnricher!>! enricherImplementationFactory) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilderExtensions.AddTraceEnricher<T>(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
virtual OpenTelemetry.Extensions.Enrichment.TraceEnricher.Enrich(ref OpenTelemetry.Extensions.Enrichment.TraceEnrichmentBag traceEnrichmentBag) -> void
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>.Enrich(T enrichmentBag) -> void
abstract OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>.Enrich(in T enrichmentBag) -> void
Microsoft.Extensions.DependencyInjection.OpenTelemetryEnrichmentServiceCollectionExtensions
OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>
OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>.BaseEnricher() -> void
Expand All @@ -17,4 +17,3 @@ static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilde
static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilderExtensions.AddTraceEnricher(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action<OpenTelemetry.Extensions.Enrichment.TraceEnrichmentBag>! enrichmentAction) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilderExtensions.AddTraceEnricher(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Func<System.IServiceProvider!, OpenTelemetry.Extensions.Enrichment.TraceEnricher!>! enricherImplementationFactory) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilderExtensions.AddTraceEnricher<T>(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
virtual OpenTelemetry.Extensions.Enrichment.TraceEnricher.Enrich(ref OpenTelemetry.Extensions.Enrichment.TraceEnrichmentBag traceEnrichmentBag) -> void
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
abstract OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>.Enrich(T enrichmentBag) -> void
abstract OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>.Enrich(in T enrichmentBag) -> void
Microsoft.Extensions.DependencyInjection.OpenTelemetryEnrichmentServiceCollectionExtensions
OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>
OpenTelemetry.Extensions.Enrichment.BaseEnricher<T>.BaseEnricher() -> void
Expand All @@ -17,4 +17,3 @@ static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilde
static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilderExtensions.AddTraceEnricher(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action<OpenTelemetry.Extensions.Enrichment.TraceEnrichmentBag>! enrichmentAction) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilderExtensions.AddTraceEnricher(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Func<System.IServiceProvider!, OpenTelemetry.Extensions.Enrichment.TraceEnricher!>! enricherImplementationFactory) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Extensions.Enrichment.OpenTelemetryEnrichmentProviderBuilderExtensions.AddTraceEnricher<T>(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
virtual OpenTelemetry.Extensions.Enrichment.TraceEnricher.Enrich(ref OpenTelemetry.Extensions.Enrichment.TraceEnrichmentBag traceEnrichmentBag) -> void
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Extensions.Enrichment/BaseEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ protected BaseEnricher()
{
}

public abstract void Enrich(T enrichmentBag);
public abstract void Enrich(in T enrichmentBag);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public EnrichmentActions(IEnumerable<Action<TraceEnrichmentBag>> actions)
this.actions = actions.ToArray();
}

public override void Enrich(TraceEnrichmentBag enrichmentBag)
public override void Enrich(in TraceEnrichmentBag enrichmentBag)
{
for (int i = 0; i < this.actions.Length; i++)
{
Expand Down
Loading

0 comments on commit 70acd21

Please sign in to comment.