Skip to content

Commit 50de381

Browse files
authored
Merge branch 'main' into corewcf
2 parents d367a75 + dee34d4 commit 50de381

File tree

13 files changed

+57
-30
lines changed

13 files changed

+57
-30
lines changed

.github/workflows/format-native.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # tag: v6.0.1
4848

4949
- name: Setup Go
50-
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # tag: v6.1.0
50+
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # tag: v6.2.0
5151
with:
5252
go-version: '1.23.5'
5353
cache: false # Suppress a warning given that there are no go.sum files in the repo

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h
1717
- Support for file-based configuration of the IL rewrite for
1818
SqlClient instrumentation setting
1919
- Add support for `StackExchange.Redis` for applications targeting .NET Framework.
20+
- Automatically set the `service.instance.id` resource attribute if not provided.
2021
- Support for [CoreWCF.Primitives](https://www.nuget.org/packages/CoreWCF.Primitives/)
2122
traces instrumentation for versions `1.8.0`+.
2223

docker/debian-arm64.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:9.0.308-bookworm-slim@sha256:51060ced0e5dc1282a587a092783132ba8b0ec25150d3bc61e99bf0ef2d62593
1+
FROM mcr.microsoft.com/dotnet/sdk:9.0.308-bookworm-slim@sha256:ddc0e6d46a459d1c740dd9e3d2668bc50f24d420274fb751e39cbf75154b9485
22
# There is no official base image for .NET SDK 10+ on Debian, so install .NET10 via dotnet-install
33

44
RUN apt-get update && \

docker/debian.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:9.0.308-bookworm-slim@sha256:51060ced0e5dc1282a587a092783132ba8b0ec25150d3bc61e99bf0ef2d62593
1+
FROM mcr.microsoft.com/dotnet/sdk:9.0.308-bookworm-slim@sha256:ddc0e6d46a459d1c740dd9e3d2668bc50f24d420274fb751e39cbf75154b9485
22
# There is no official base image for .NET SDK 10+ on Debian, so install .NET10 via apt-get
33

44
RUN wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \

src/OpenTelemetry.AutoInstrumentation/Configurations/ResourceConfigurator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public static ResourceBuilder CreateResourceBuilder(ResourceSettings resourceSet
4848
resourceBuilder.AddAttributes([new(Constants.ResourceAttributes.AttributeServiceName, ServiceNameConfigurator.GetFallbackServiceName())]);
4949
}
5050

51+
if (resource.Attributes.All(kvp => kvp.Key != Constants.ResourceAttributes.AttributeServiceInstanceId))
52+
{
53+
// service.instance.id was not configured yet use the fallback.
54+
resourceBuilder.AddAttributes([new(Constants.ResourceAttributes.AttributeServiceInstanceId, Guid.NewGuid().ToString())]);
55+
}
56+
5157
var pluginManager = Instrumentation.PluginManager;
5258
if (pluginManager != null)
5359
{

src/OpenTelemetry.AutoInstrumentation/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static class HttpSpanAttributes
2727
public static class ResourceAttributes
2828
{
2929
public const string AttributeServiceName = "service.name";
30+
public const string AttributeServiceInstanceId = "service.instance.id";
3031
}
3132

3233
public static class ConfigurationValues

test/IntegrationTests/AspNetTests.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace IntegrationTests;
1010

11-
public class AspNetTests
11+
public class AspNetTests(ITestOutputHelper output)
1212
{
1313
private const string ServiceName = "TestApplication.AspNet.NetFramework";
1414

@@ -22,11 +22,6 @@ public class AspNetTests
2222
}
2323
};
2424

25-
public AspNetTests(ITestOutputHelper output)
26-
{
27-
Output = output;
28-
}
29-
3025
public enum Gac
3126
{
3227
/// <summary>
@@ -53,7 +48,7 @@ public enum AppPoolMode
5348
Integrated
5449
}
5550

56-
private ITestOutputHelper Output { get; }
51+
private ITestOutputHelper Output { get; } = output;
5752

5853
[Theory]
5954
[Trait("Category", "EndToEnd")]
@@ -179,8 +174,9 @@ public async Task TracesResource()
179174
// on the firewall.
180175
using var collector = new MockSpansCollector(Output, host: "*");
181176
using var fwPort = FirewallHelper.OpenWinPort(collector.Port, Output);
182-
collector.ResourceExpector.Expect("service.name", ServiceName); // this is set via env var in Dockerfile and Wep.config, but env var has precedence
183-
collector.ResourceExpector.Expect("deployment.environment.name", "test"); // this is set via Wep.config
177+
collector.ResourceExpector.Expect("service.name", ServiceName); // this is set via env var in Dockerfile and Web.config, but env var has precedence
178+
collector.ResourceExpector.Expect("deployment.environment.name", "test"); // this is set via Web.config
179+
collector.ResourceExpector.Matches("service.instance.id", "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"); // automatically generated
184180

185181
var collectorUrl = $"http://{DockerNetworkHelper.IntegrationTestsGateway}:{collector.Port}";
186182

test/IntegrationTests/Helpers/OtlpResourceExpector.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace IntegrationTests.Helpers;
1111

1212
internal sealed class OtlpResourceExpector : IDisposable
1313
{
14-
private readonly List<ResourceExpectation> _resourceExpectations = new();
15-
private readonly List<string> _existenceChecks = new();
14+
private readonly List<ResourceExpectation> _resourceExpectations = [];
15+
private readonly List<string> _existenceChecks = [];
1616

1717
private readonly ManualResetEvent _resourceAttributesEvent = new(false); // synchronizes access to _resourceAttributes
1818
private RepeatedField<KeyValue>? _resourceAttributes; // protobuf type
@@ -47,6 +47,11 @@ public void Expect(string key, long value)
4747
_resourceExpectations.Add(new ResourceExpectation(key, value));
4848
}
4949

50+
public void Matches(string key, string regex)
51+
{
52+
_resourceExpectations.Add(new ResourceExpectation(key, regex, isRegex: true));
53+
}
54+
5055
public void AssertExpectations(TimeSpan? timeout = null)
5156
{
5257
if (_resourceExpectations.Count == 0 && _existenceChecks.Count == 0)
@@ -108,12 +113,16 @@ private static void AssertResource(List<ResourceExpectation> resourceExpectation
108113
continue;
109114
}
110115

111-
if (missingExpectations[i].StringValue != null && resourceAttribute.Value.StringValue != missingExpectations[i].StringValue)
116+
var expectation = missingExpectations[i];
117+
118+
if (expectation.StringValue != null &&
119+
((!expectation.IsRegex && resourceAttribute.Value.StringValue != expectation.StringValue) ||
120+
(expectation.IsRegex && !System.Text.RegularExpressions.Regex.IsMatch(resourceAttribute.Value.StringValue, expectation.StringValue))))
112121
{
113122
continue;
114123
}
115124

116-
if (missingExpectations[i].IntValue != null && resourceAttribute.Value.IntValue != missingExpectations[i].IntValue)
125+
if (expectation.IntValue != null && resourceAttribute.Value.IntValue != expectation.IntValue)
117126
{
118127
continue;
119128
}
@@ -132,15 +141,17 @@ private static void AssertResource(List<ResourceExpectation> resourceExpectation
132141

133142
private static void FailResource(List<ResourceExpectation> missingExpectations, RepeatedField<KeyValue>? attributes)
134143
{
135-
attributes ??= new();
144+
attributes ??= [];
136145

137146
var message = new StringBuilder();
138147
message.AppendLine();
139148

140149
message.AppendLine("Missing resource expectations:");
141150
foreach (var expectation in missingExpectations)
142151
{
143-
var value = !string.IsNullOrEmpty(expectation.StringValue) ? expectation.StringValue : expectation.IntValue!.Value.ToString(CultureInfo.InvariantCulture);
152+
var value = string.IsNullOrEmpty(expectation.StringValue)
153+
? expectation.IntValue!.Value.ToString(CultureInfo.InvariantCulture)
154+
: expectation.IsRegex ? $"/{expectation.StringValue}/" : expectation.StringValue;
144155
message.AppendLine(CultureInfo.InvariantCulture, $" - \"{expectation.Key}={value}\"");
145156
}
146157

@@ -156,10 +167,11 @@ private static void FailResource(List<ResourceExpectation> missingExpectations,
156167

157168
private sealed class ResourceExpectation
158169
{
159-
public ResourceExpectation(string key, string stringValue)
170+
public ResourceExpectation(string key, string stringValue, bool isRegex = false)
160171
{
161172
Key = key;
162173
StringValue = stringValue;
174+
IsRegex = isRegex;
163175
}
164176

165177
public ResourceExpectation(string key, long intValue)
@@ -173,5 +185,7 @@ public ResourceExpectation(string key, long intValue)
173185
public string? StringValue { get; }
174186

175187
public long? IntValue { get; }
188+
189+
public bool IsRegex { get; }
176190
}
177191
}

test/IntegrationTests/Helpers/OtlpResourceExpectorExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal static class OtlpResourceExpectorExtensions
1010
public static void ExpectStandardResources(this OtlpResourceExpector resourceExpector, int processId, string serviceName)
1111
{
1212
resourceExpector.Expect("service.name", serviceName); // this is set via env var and App.config, but env var has precedence
13+
resourceExpector.Matches("service.instance.id", "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$");
1314
#if NETFRAMEWORK
1415
resourceExpector.Expect("deployment.environment.name", "test"); // this is set via App.config
1516
#endif
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FROM postgres:18.1@sha256:bfe50b2b0ddd9b55eadedd066fe24c7c6fe06626185b73358c480ea37868024d
1+
FROM postgres:18.1@sha256:fdd16e63f6c8ab50d422e4896b0d43d45fb72aa08bd33e4f5bda89bc4fbce98d

0 commit comments

Comments
 (0)