Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OLD] Add OpenTelemetry Instrumentation #412

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[*.json]
indent_size = 2

[src/NATS.Client.Core/NaCl/**.cs]
generated_code = true

Expand Down
18 changes: 18 additions & 0 deletions NATS.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4827B3EC-73D8-436D-AE2A-5E29AC95FD0C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sandbox", "sandbox", "{95A69671-16CA-4133-981C-CC381B7AAA30}"
ProjectSection(SolutionItems) = preProject
sandbox\shell.nix = sandbox\shell.nix
sandbox\Directory.Build.props = sandbox\Directory.Build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{C526E8AB-739A-48D7-8FC4-048978C9B650}"
EndProject
Expand Down Expand Up @@ -101,6 +105,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NATS.Net.DocsExamples", "te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NATS.Client.Hosting.Tests", "tests\NATS.Client.Hosting.Tests\NATS.Client.Hosting.Tests.csproj", "{766C2486-34C3-4DD1-B31C-540C17C044B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NATS.Net.OpenTelemetry", "src\NATS.Net.OpenTelemetry\NATS.Net.OpenTelemetry.csproj", "{EC6A3E38-3906-4720-921D-BA1E439B4DE7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Core", "sandbox\Example.Core\Example.Core.csproj", "{8BFBB88D-7596-44B9-BF67-5402A662F244}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -267,6 +275,14 @@ Global
{766C2486-34C3-4DD1-B31C-540C17C044B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{766C2486-34C3-4DD1-B31C-540C17C044B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{766C2486-34C3-4DD1-B31C-540C17C044B0}.Release|Any CPU.Build.0 = Release|Any CPU
{EC6A3E38-3906-4720-921D-BA1E439B4DE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC6A3E38-3906-4720-921D-BA1E439B4DE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC6A3E38-3906-4720-921D-BA1E439B4DE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC6A3E38-3906-4720-921D-BA1E439B4DE7}.Release|Any CPU.Build.0 = Release|Any CPU
{8BFBB88D-7596-44B9-BF67-5402A662F244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8BFBB88D-7596-44B9-BF67-5402A662F244}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BFBB88D-7596-44B9-BF67-5402A662F244}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BFBB88D-7596-44B9-BF67-5402A662F244}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -313,6 +329,8 @@ Global
{6A7B9B9F-BFA4-4A6D-9006-0AAF597FC6DD} = {4827B3EC-73D8-436D-AE2A-5E29AC95FD0C}
{389C05EB-A0B3-4097-8C1F-4D55818438CC} = {C526E8AB-739A-48D7-8FC4-048978C9B650}
{766C2486-34C3-4DD1-B31C-540C17C044B0} = {C526E8AB-739A-48D7-8FC4-048978C9B650}
{EC6A3E38-3906-4720-921D-BA1E439B4DE7} = {4827B3EC-73D8-436D-AE2A-5E29AC95FD0C}
{8BFBB88D-7596-44B9-BF67-5402A662F244} = {95A69671-16CA-4133-981C-CC381B7AAA30}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8CBB7278-D093-448E-B3DE-B5991209A1AA}
Expand Down
4 changes: 3 additions & 1 deletion sandbox/BlazorWasm/Client/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"BlazorWasm": {
"commandName": "Project",
Expand All @@ -7,7 +8,8 @@
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Development",
"OTEL_SERVICE_NAME": "BlazorWasm"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions sandbox/BlazorWasm/Server/BlazorWasm.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.4" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Example.Core\Example.Core.csproj" />
<ProjectReference Include="..\Client\BlazorWasm.Client.csproj" />
<ProjectReference Include="..\Shared\BlazorWasm.Shared.csproj" />
</ItemGroup>
Expand Down
11 changes: 10 additions & 1 deletion sandbox/BlazorWasm/Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
using BlazorWasm.Server.NatsServices;
using NATS.Client.Core;
using Example.Core;
using NATS.Client.Hosting;
using NATS.Client.Serializers.Json;
using OpenTelemetry.Trace;

TracingSetup.SetSandboxEnv();

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
.WithTracing(o => o
.AddAspNetCoreInstrumentation()
.AddNatsInstrumentation()
.AddOtlpExporter());

// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
Expand Down
22 changes: 12 additions & 10 deletions sandbox/BlazorWasm/Server/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"profiles": {
"BlazorWasm.Server": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"BlazorWasm.Server": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"OTEL_SERVICE_NAME": "BlazorWasm.Server"
}
}
}
}
13 changes: 13 additions & 0 deletions sandbox/ConsoleApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"ConsoleApp": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"OTEL_SERVICE_NAME": "ConsoleApp"
}
}
}
}
12 changes: 12 additions & 0 deletions sandbox/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<!-- Multi-layer .props files must be imported manually -->
<Import Project="..\Directory.Build.props" />

<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\src\NATS.Net.OpenTelemetry\NATS.Net.OpenTelemetry.csproj"/>
<PackageReference Include="OpenTelemetry" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.6.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\NATS.Client.Core\NATS.Client.Core.csproj" />
<ProjectReference Include="..\..\src\NATS.Client.Serializers.Json\NATS.Client.Serializers.Json.csproj" />
<ProjectReference Include="..\Example.Core\Example.Core.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions sandbox/Example.Core.PublishHeaders/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// > nats sub bar.*

using Example.Core;
using Microsoft.Extensions.Logging;
using NATS.Client.Core;
using NATS.Client.Serializers.Json;

using var tracer = TracingSetup.RunSandboxTracing();

var subject = "bar.xyz";
var options = NatsOpts.Default with
{
Expand Down
13 changes: 13 additions & 0 deletions sandbox/Example.Core.PublishHeaders/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Example.Core.PublishHeaders": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"OTEL_SERVICE_NAME": "Example.Core.PublishHeaders"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<ItemGroup>
<ProjectReference Include="..\..\src\NATS.Client.Core\NATS.Client.Core.csproj" />
<ProjectReference Include="..\..\src\NATS.Client.Serializers.Json\NATS.Client.Serializers.Json.csproj" />

<ProjectReference Include="..\Example.Core\Example.Core.csproj" />

</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions sandbox/Example.Core.PublishModel/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// > nats sub bar.*

using Example.Core;
using Microsoft.Extensions.Logging;
using NATS.Client.Core;
using NATS.Client.Serializers.Json;

using var tracer = TracingSetup.RunSandboxTracing();

var subject = "bar.xyz";
var options = NatsOpts.Default with
{
Expand All @@ -13,6 +17,7 @@
Print("[CON] Connecting...\n");

await using var connection = new NatsConnection(options);
await connection.ConnectAsync();

for (var i = 0; i < 10; i++)
{
Expand Down
13 changes: 13 additions & 0 deletions sandbox/Example.Core.PublishModel/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Example.Core.PublishModel": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"OTEL_SERVICE_NAME": "Example.Core.PublishModel"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\NATS.Client.Core\NATS.Client.Core.csproj" />
<ProjectReference Include="..\..\src\NATS.Client.Serializers.Json\NATS.Client.Serializers.Json.csproj" />
<ProjectReference Include="..\Example.Core\Example.Core.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions sandbox/Example.Core.SubscribeHeaders/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// > nats pub bar.xyz --count=10 "my_message_{{ Count }}" -H X-Foo:Baz

using Example.Core;
using Microsoft.Extensions.Logging;
using NATS.Client.Core;
using NATS.Client.Serializers.Json;

using var tracer = TracingSetup.RunSandboxTracing();

var subject = "bar.*";
var options = NatsOpts.Default with
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Example.Core.SubscribeHeaders": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"OTEL_SERVICE_NAME": "Example.Core.SubscribeHeaders"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\NATS.Client.Core\NATS.Client.Core.csproj" />
<ProjectReference Include="..\..\src\NATS.Client.Serializers.Json\NATS.Client.Serializers.Json.csproj" />
<ProjectReference Include="..\Example.Core\Example.Core.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions sandbox/Example.Core.SubscribeModel/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Example.Core;
using Microsoft.Extensions.Logging;
using NATS.Client.Core;
using NATS.Client.Serializers.Json;

using var tracer = TracingSetup.RunSandboxTracing();

var subject = "bar.*";
var options = NatsOpts.Default with
{
Expand All @@ -17,6 +20,7 @@

await foreach (var msg in connection.SubscribeAsync<Bar>(subject))
{
using var activity = msg.StartChildActivity();
Print($"[RCV] {msg.Subject}: {msg.Data}\n");
}

Expand Down
13 changes: 13 additions & 0 deletions sandbox/Example.Core.SubscribeModel/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Example.Core.SubscribeModel": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"OTEL_SERVICE_NAME": "Example.Core.SubscribeModel"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\NATS.Client.Core\NATS.Client.Core.csproj" />
<ProjectReference Include="..\Example.Core\Example.Core.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions sandbox/Example.Core.SubscribeQueueGroup/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// > nats pub foo.xyz --count=10 "my_message_{{ Count }}"

using Example.Core;
using Microsoft.Extensions.Logging;
using NATS.Client.Core;

using var tracer = TracingSetup.RunSandboxTracing();

var subject = "foo.*";
var options = NatsOpts.Default with { LoggerFactory = LoggerFactory.Create(builder => builder.AddConsole()) };

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Example.Core.SubscribeQueueGroup": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"OTEL_SERVICE_NAME": "Example.Core.SubscribeQueueGroup"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\NATS.Client.Core\NATS.Client.Core.csproj" />
<ProjectReference Include="..\Example.Core\Example.Core.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions sandbox/Example.Core.SubscribeRaw/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Text;
using Example.Core;
using Microsoft.Extensions.Logging;
using NATS.Client.Core;

using var tracer = TracingSetup.RunSandboxTracing();

var subject = "foo.*";
var options = NatsOpts.Default with { LoggerFactory = LoggerFactory.Create(builder => builder.AddConsole()) };

Expand Down
13 changes: 13 additions & 0 deletions sandbox/Example.Core.SubscribeRaw/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Example.Core.SubscribeRaw": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"OTEL_SERVICE_NAME": "Example.Core.SubscribeRaw"
}
}
}
}
13 changes: 13 additions & 0 deletions sandbox/Example.Core/Example.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NATS.Client.Core\NATS.Client.Core.csproj" />
</ItemGroup>

</Project>
Loading
Loading