Skip to content

Commit cad3d90

Browse files
authored
Remove config option from tracing libraries (#59)
* Remove config option for tracing libraries * Improve Pyroscope tracing library helpers naming consistency
1 parent 4ec8b3a commit cad3d90

File tree

15 files changed

+106
-200
lines changed

15 files changed

+106
-200
lines changed

.github/workflows/build_tracing_packages.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
dotnet-version: '6.0'
2020
- run: dotnet build -c Release
21-
working-directory: Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTracing
21+
working-directory: Pyroscope/Pyroscope.OpenTracing
2222
build-tracing-lib-opentelemetry:
2323
runs-on: ubuntu-latest
2424
steps:
@@ -30,4 +30,4 @@ jobs:
3030
with:
3131
dotnet-version: '6.0'
3232
- run: dotnet build -c Release
33-
working-directory: Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTelemetry
33+
working-directory: Pyroscope/Pyroscope.OpenTelemetry

.github/workflows/tag_tracing_opentelemetry_helper.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ jobs:
1717
with:
1818
dotnet-version: '6.0'
1919
- run: dotnet build -c Release
20-
working-directory: Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTelemetry
20+
working-directory: Pyroscope/Pyroscope.OpenTelemetry
2121
- name: Publish the package to nuget.org
2222
run: dotnet nuget push bin/Release/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
23-
working-directory: Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTelemetry
23+
working-directory: Pyroscope/Pyroscope.OpenTelemetry
2424
env:
2525
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
2626
- name: Release
2727
uses: softprops/action-gh-release@v1
2828
if: startsWith(github.ref, 'refs/tags/')
2929
with:
3030
files: |
31-
./Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTelemetry/bin/Release/net6.0/Pyroscope.Tracing.OpenTelemetry.dll
32-
./Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTelemetry/bin/Release/Pyroscope.Tracing.OpenTelemetry*.nupkg
31+
./Pyroscope/Pyroscope.OpenTelemetry/bin/Release/net6.0/Pyroscope.OpenTelemetry.dll
32+
./Pyroscope/Pyroscope.OpenTelemetry/bin/Release/Pyroscope.OpenTelemetry*.nupkg

.github/workflows/tag_tracing_opentracing_helper.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ jobs:
1717
with:
1818
dotnet-version: '6.0'
1919
- run: dotnet build -c Release
20-
working-directory: Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTracing
20+
working-directory: Pyroscope/Pyroscope.OpenTracing
2121
- name: Publish the package to nuget.org
2222
run: dotnet nuget push bin/Release/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
23-
working-directory: Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTracing
23+
working-directory: Pyroscope/Pyroscope.OpenTracing
2424
env:
2525
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
2626
- name: Release
2727
uses: softprops/action-gh-release@v1
2828
if: startsWith(github.ref, 'refs/tags/')
2929
with:
3030
files: |
31-
./Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTracing/bin/Release/net6.0/Pyroscope.Tracing.OpenTracing.dll
32-
./Pyroscope/Pyroscope.Tracing/Pyroscope.Tracing.OpenTracing/bin/Release/Pyroscope.Tracing.OpenTracing*.nupkg
31+
./Pyroscope/Pyroscope.OpenTracing/bin/Release/net6.0/Pyroscope.OpenTracing.dll
32+
./Pyroscope/Pyroscope.OpenTracing/bin/Release/Pyroscope.OpenTracing*.nupkg
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8-
<PackageVersion>0.1.0</PackageVersion>
9-
<AssemblyVersion>0.1.0</AssemblyVersion>
10-
<FileVersion>0.1.0</FileVersion>
8+
<PackageVersion>0.2.0</PackageVersion>
9+
<AssemblyVersion>0.2.0</AssemblyVersion>
10+
<FileVersion>0.2.0</FileVersion>
1111
<LangVersion>10</LangVersion>
1212
<PackageReadmeFile>README.md</PackageReadmeFile>
1313
</PropertyGroup>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.5.002.0
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pyroscope.Tracing.OpenTelemetry", "Pyroscope.Tracing.OpenTelemetry.csproj", "{42160563-B7D4-41D6-89DE-9CEDEEB542AA}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pyroscope.OpenTelemetry", "Pyroscope.OpenTelemetry.csproj", "{42160563-B7D4-41D6-89DE-9CEDEEB542AA}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Diagnostics;
2+
using OpenTelemetry;
3+
4+
namespace Pyroscope.OpenTelemetry;
5+
6+
public class PyroscopeSpanProcessor : BaseProcessor<Activity>
7+
{
8+
private const string ProfileIdSpanTagKey = "pyroscope.profile.id";
9+
10+
public override void OnStart(Activity data)
11+
{
12+
if (!IsRootSpan(data))
13+
{
14+
return;
15+
}
16+
17+
try
18+
{
19+
var spanId = data.SpanId.ToString();
20+
var spanIdLong = Convert.ToUInt64(spanId.ToUpper(), 16);
21+
22+
// Establish a two-way connection between the span and profiling data
23+
Profiler.Instance.SetProfileId(spanIdLong);
24+
data.AddTag(ProfileIdSpanTagKey, spanId);
25+
}
26+
catch (Exception ex)
27+
{
28+
Console.WriteLine($"Caught exception while setting profile id in profiler instance: {ex.Message}");
29+
}
30+
}
31+
32+
public override void OnEnd(Activity data)
33+
{
34+
if (IsRootSpan(data))
35+
{
36+
Profiler.Instance.SetProfileId(0); // TODO: Replace with ResetContext()
37+
return;
38+
}
39+
}
40+
41+
private static bool IsRootSpan(Activity data)
42+
{
43+
var parent = data.Parent;
44+
return parent == null || parent.HasRemoteParent;
45+
}
46+
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See https://grafana.com/docs/pyroscope/latest/configure-client/trace-span-profil
1313
Add the following package to your project:
1414

1515
```shell
16-
dotnet add package Pyroscope.Tracing.OpenTelemetry
16+
dotnet add package Pyroscope.OpenTelemetry
1717
```
1818

1919
Register the `PyroscopeSpanProcessor` in your OpenTelemetry integration:
@@ -27,9 +27,7 @@ builder.Services.AddOpenTelemetry()
2727
.AddAspNetCoreInstrumentation()
2828
.AddConsoleExporter()
2929
.AddOtlpExporter()
30-
.AddProcessor(new PyroscopeSpanProcessor.Builder()
31-
.WithRootSpanOnly(true)
32-
.Build());
30+
.AddProcessor(new Pyroscope.OpenTelemetry.PyroscopeSpanProcessor());
3331
});
3432

3533
```
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8-
<PackageVersion>0.1.0</PackageVersion>
9-
<AssemblyVersion>0.1.0</AssemblyVersion>
10-
<FileVersion>0.1.0</FileVersion>
8+
<PackageVersion>0.2.0</PackageVersion>
9+
<AssemblyVersion>0.2.0</AssemblyVersion>
10+
<FileVersion>0.2.0</FileVersion>
1111
<LangVersion>10</LangVersion>
1212
<PackageReadmeFile>README.md</PackageReadmeFile>
1313
</PropertyGroup>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.5.002.0
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pyroscope.Tracing.OpenTracing", "Pyroscope.Tracing.OpenTracing.csproj", "{311866C4-042D-4F43-B025-CC142FDD02B3}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pyroscope.OpenTracing", "Pyroscope.OpenTracing.csproj", "{311866C4-042D-4F43-B025-CC142FDD02B3}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
using OpenTracing;
22
using OpenTracing.Tag;
33

4-
namespace Pyroscope.Tracing.OpenTracing;
4+
namespace Pyroscope.OpenTracing;
55

66
public class PyroscopeSpanBuilder : ISpanBuilder
77
{
88
private const string ProfileIdSpanTagKey = "pyroscope.profile.id";
99

1010
private readonly ISpanBuilder _delegate;
11-
private readonly Config _config;
1211
private ISpanContext? _parent;
1312

14-
internal PyroscopeSpanBuilder(Config config, ISpanBuilder spanBuilder, ISpanContext? parent)
13+
internal PyroscopeSpanBuilder(ISpanBuilder spanBuilder, ISpanContext? parent)
1514
{
16-
_config = config;
1715
_delegate = spanBuilder;
1816
_parent = parent;
1917
}
@@ -29,19 +27,19 @@ public IScope StartActive()
2927
{
3028
var scope = _delegate.StartActive();
3129
ConnectSpanWithProfiling(scope.Span);
32-
return new PyroscopeScope(_config, scope, _parent);
30+
return new PyroscopeScope(scope, _parent);
3331
}
3432

3533
public IScope StartActive(bool finishSpanOnDispose)
3634
{
3735
var scope = _delegate.StartActive(finishSpanOnDispose);
3836
ConnectSpanWithProfiling(scope.Span);
39-
return new PyroscopeScope(_config, scope, _parent);
37+
return new PyroscopeScope(scope, _parent);
4038
}
4139

4240
private void ConnectSpanWithProfiling(ISpan span)
4341
{
44-
if (_parent != null && _config.RootSpanOnly)
42+
if (_parent != null)
4543
{
4644
return;
4745
}
@@ -139,15 +137,13 @@ public ISpanBuilder IgnoreActiveSpan()
139137

140138
class PyroscopeScope : IScope
141139
{
142-
private readonly Config _config;
143140
private readonly IScope _delegate;
144141
private readonly ISpanContext? _parent;
145142

146143
public ISpan Span => _delegate.Span;
147144

148-
internal PyroscopeScope(Config _config, IScope _delegate, ISpanContext? _parent)
145+
internal PyroscopeScope(IScope _delegate, ISpanContext? _parent)
149146
{
150-
this._config = _config;
151147
this._delegate = _delegate;
152148
this._parent = _parent;
153149
}
@@ -160,21 +156,6 @@ public void Dispose()
160156
Profiler.Instance.SetProfileId(0); // TODO: Replace with ResetContext()
161157
return;
162158
}
163-
if (_config.RootSpanOnly)
164-
{
165-
return;
166-
}
167-
try
168-
{
169-
var spanId = _parent.SpanId;
170-
var spanIdLong = Convert.ToUInt64(spanId.ToUpper(), 16);
171-
172-
Profiler.Instance.SetProfileId(spanIdLong);
173-
}
174-
catch (Exception ex)
175-
{
176-
Console.WriteLine($"Caught exception while setting profile id in profiler instance: {ex.Message}");
177-
}
178159
}
179160
}
180161
}

0 commit comments

Comments
 (0)