|
| 1 | +// |
| 2 | +// Copyright Grafana Labs |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | +// |
| 5 | + |
| 6 | +using System.Linq; |
| 7 | +using OpenTelemetry.Resources; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Grafana.OpenTelemetry.Tests |
| 11 | +{ |
| 12 | + public class ResourceBuilderExtensionTest |
| 13 | + { |
| 14 | + [Fact] |
| 15 | + public void StableServiceInstanceId() |
| 16 | + { |
| 17 | + var resource1 = ResourceBuilder |
| 18 | + .CreateEmpty() |
| 19 | + .AddGrafanaResource(new GrafanaOpenTelemetrySettings()) |
| 20 | + .Build() |
| 21 | + .Attributes |
| 22 | + .ToDictionary(x => x.Key, x => x.Value); |
| 23 | + var resource2 = ResourceBuilder |
| 24 | + .CreateEmpty() |
| 25 | + .AddGrafanaResource(new GrafanaOpenTelemetrySettings()) |
| 26 | + .Build() |
| 27 | + .Attributes |
| 28 | + .ToDictionary(x => x.Key, x => x.Value); |
| 29 | + |
| 30 | + Assert.NotNull(resource1["service.instance.id"]); |
| 31 | + Assert.NotNull(resource2["service.instance.id"]); |
| 32 | + Assert.Equal(resource1["service.instance.id"], resource2["service.instance.id"]); |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public void OverrideServiceInstanceId() |
| 37 | + { |
| 38 | + var settings = new GrafanaOpenTelemetrySettings |
| 39 | + { |
| 40 | + ServiceInstanceId = "test-id" |
| 41 | + }; |
| 42 | + var resource1 = ResourceBuilder |
| 43 | + .CreateEmpty() |
| 44 | + .AddGrafanaResource(settings) |
| 45 | + .Build() |
| 46 | + .Attributes |
| 47 | + .ToDictionary(x => x.Key, x => x.Value); |
| 48 | + |
| 49 | + Assert.NotNull(resource1["service.instance.id"]); |
| 50 | + Assert.Equal(resource1["service.instance.id"], "test-id"); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments