Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Reflection;
using EventStore.Core.Diagnostics;
using FluentAssertions;
using Xunit;

namespace EventStore.Core.XUnit.Tests.OpenTelemetry;

public class TelemetryMeterFactoryTests
{
[Fact]
public void UsesTheCurrentServerVersionForTheInstrumentationScope()
{
using var meter = TelemetryMeterFactory.Create("test-scope");
var informationalVersion = typeof(TelemetryMeterFactory).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!
.InformationalVersion;

meter.Name.Should().Be("test-scope");
meter.Version.Should().Be(informationalVersion.Split('+', 2)[0]);
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void RejectsMissingInstrumentationScopeNames(string instrumentationScopeName)
{
var action = () => TelemetryMeterFactory.Create(instrumentationScopeName);

action.Should().Throw<ArgumentException>();
}
}
29 changes: 29 additions & 0 deletions src/EventStore.Core/Diagnostics/TelemetryMeterFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Diagnostics.Metrics;
using System.Reflection;

namespace EventStore.Core.Diagnostics;

public static class TelemetryMeterFactory
{
private static readonly string InstrumentationScopeVersion = GetInstrumentationScopeVersion();

public static Meter Create(string instrumentationScopeName)
{
ArgumentException.ThrowIfNullOrWhiteSpace(instrumentationScopeName);
return new Meter(instrumentationScopeName, InstrumentationScopeVersion);
}

private static string GetInstrumentationScopeVersion()
{
var informationalVersion = typeof(TelemetryMeterFactory).Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion;
if (string.IsNullOrWhiteSpace(informationalVersion))
{
throw new InvalidOperationException("The telemetry assembly has no informational version.");
}

return informationalVersion.Split('+', 2)[0];
}
}
4 changes: 2 additions & 2 deletions src/EventStore.Core/MetricsBootstrapper.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using EventStore.Core.Bus;
using EventStore.Core.Diagnostics;
using EventStore.Core.Index;
using EventStore.Core.Metrics;
using EventStore.Core.Services.VNode;
Expand Down Expand Up @@ -84,7 +84,7 @@ public static void Bootstrap(
return;
}

var coreMeter = new Meter("EventStore.Core", version: "1.0.0");
var coreMeter = TelemetryMeterFactory.Create("EventStore.Core");
var statusMetric = new StatusMetric(coreMeter, "eventstore-statuses");
var grpcMethodMetric = new DurationMetric(coreMeter, "eventstore-grpc-method-duration");
var gossipLatencyMetric = new DurationMetric(coreMeter, "eventstore-gossip-latency");
Expand Down
4 changes: 2 additions & 2 deletions src/EventStore.Projections.Core/ProjectionsSubsystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Threading.Tasks;
using DotNext;
Expand All @@ -9,6 +8,7 @@
using EventStore.Core;
using EventStore.Core.Bus;
using EventStore.Core.Data;
using EventStore.Core.Diagnostics;
using EventStore.Core.Messages;
using EventStore.Core.Messaging;
using EventStore.Core.Services.AwakeReaderService;
Expand Down Expand Up @@ -205,7 +205,7 @@ private void ConfigureProjectionMetrics(bool isEnabled)
return;
}

var projectionMeter = new Meter("EventStore.Projections.Core", version: "1.0.0");
var projectionMeter = TelemetryMeterFactory.Create("EventStore.Projections.Core");

var tracker = new ProjectionTracker();
_projectionTracker = tracker;
Expand Down
Loading