From d8ffb92b5b1e74461a43385fe893109972c6c905 Mon Sep 17 00:00:00 2001 From: Liudmila Molkova Date: Wed, 9 Nov 2022 09:36:28 -0800 Subject: [PATCH] review --- .../CHANGELOG.md | 3 +++ .../EventCountersMetrics.cs | 6 ++---- .../EventCountersMetricsTests.cs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.EventCounters/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.EventCounters/CHANGELOG.md index f3f36b2d94..aecb87cb95 100644 --- a/src/OpenTelemetry.Instrumentation.EventCounters/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.EventCounters/CHANGELOG.md @@ -3,6 +3,9 @@ ## Unreleased * Update OpenTelemetry.Api to 1.3.1. +* Changed `EventCounter` prefix to `ec` and started abbreviating event source name + when instrument name is longer that 63 characters. + ([#740](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/740)) ## 1.0.0-alpha.1 diff --git a/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersMetrics.cs b/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersMetrics.cs index deec1840e7..9096e20ed1 100644 --- a/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersMetrics.cs +++ b/src/OpenTelemetry.Instrumentation.EventCounters/EventCountersMetrics.cs @@ -140,8 +140,7 @@ private static string GetInstrumentName(string sourceName, string eventName) return string.Concat(Prefix, ".", sourceName, ".", eventName); } - int maxEventSourceNameLength = MaxInstrumentNameLength - Prefix.Length - 2 - eventName.Length; - var abbreviation = new StringBuilder(maxEventSourceNameLength); + var abbreviation = new StringBuilder(sourceName.Length); int ind = 0; while (ind >= 0 && ind < sourceName.Length) { @@ -192,10 +191,9 @@ private void UpdateInstrumentWithEvent(bool isGauge, string eventSourceName, str ValueTuple metricKey = new(eventSourceName, name); _ = this.values.AddOrUpdate(metricKey, value, isGauge ? (_, _) => value : (_, existing) => existing + value); - var instrumentName = GetInstrumentName(eventSourceName, name); - if (!this.instruments.ContainsKey(metricKey)) { + var instrumentName = GetInstrumentName(eventSourceName, name); Instrument instrument = isGauge ? MeterInstance.CreateObservableGauge(instrumentName, () => this.values[metricKey]) : MeterInstance.CreateObservableCounter(instrumentName, () => this.values[metricKey]); diff --git a/test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs b/test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs index 1c3069c410..4f7736469c 100644 --- a/test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs +++ b/test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs @@ -254,7 +254,7 @@ public async Task InstrumentNameTooLong() EventSource source = new("source"); // ec.s. + event name is 63; - string veryLongEventName = new string('e', 59); + string veryLongEventName = new string('e', 100); IncrementingEventCounter connections = new(veryLongEventName, source); var meterProvider = Sdk.CreateMeterProviderBuilder()