Skip to content

Commit 2a53a4a

Browse files
authored
Merge branch 'main' into cijothomas/sdk-self-obs-processor-log-processed
2 parents c5c90ff + 8592991 commit 2a53a4a

11 files changed

Lines changed: 79 additions & 14 deletions

File tree

.github/workflows/package-validation.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ jobs:
2222
persist-credentials: false
2323
show-progress: false
2424

25+
- name: Get Git commit timestamp
26+
id: get-commit-timestamp
27+
shell: pwsh
28+
run: |
29+
"epoch=$(git log -1 --pretty=%ct)" >> ${env:GITHUB_OUTPUT}
30+
2531
- name: Setup .NET
2632
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
2733

2834
- name: dotnet pack
2935
run: dotnet pack ./build/OpenTelemetry.proj --configuration Release /p:EnablePackageValidation=true /p:ExposeExperimentalFeatures=false /p:RunningDotNetPack=true
36+
env:
37+
SOURCE_DATE_EPOCH: ${{ steps.get-commit-timestamp.outputs.epoch }}
3038

3139
- name: Publish stable NuGet packages to Artifacts
3240
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
@@ -50,11 +58,19 @@ jobs:
5058
persist-credentials: false
5159
show-progress: false
5260

61+
- name: Get Git commit timestamp
62+
id: get-commit-timestamp
63+
shell: pwsh
64+
run: |
65+
"epoch=$(git log -1 --pretty=%ct)" >> ${env:GITHUB_OUTPUT}
66+
5367
- name: Setup .NET
5468
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
5569

5670
- name: dotnet pack
5771
run: dotnet pack ./build/OpenTelemetry.proj --configuration Release /p:EnablePackageValidation=true /p:ExposeExperimentalFeatures=true /p:RunningDotNetPack=true
72+
env:
73+
SOURCE_DATE_EPOCH: ${{ steps.get-commit-timestamp.outputs.epoch }}
5874

5975
- name: Publish experimental NuGet packages to Artifacts
6076
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1

.github/workflows/publish-packages-1.0.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ jobs:
5858
persist-credentials: false
5959
show-progress: false
6060

61+
- name: Get Git commit timestamp
62+
id: get-commit-timestamp
63+
shell: pwsh
64+
run: |
65+
"epoch=$(git log -1 --pretty=%ct)" >> ${env:GITHUB_OUTPUT}
66+
6167
- name: Setup .NET
6268
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
6369

@@ -97,6 +103,7 @@ jobs:
97103
shell: pwsh
98104
env:
99105
PACK_TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
106+
SOURCE_DATE_EPOCH: ${{ steps.get-commit-timestamp.outputs.epoch }}
100107
run: dotnet pack ./build/OpenTelemetry.proj --configuration Release --no-restore --no-build -p:"PackTag=${env:PACK_TAG}"
101108

102109
- name: Install NuGet package validation tools

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ To verify the integrity of a DLL inside a NuGet package use the
204204
These versions are using bundle format known from cosign 3.0+.
205205

206206
```bash
207-
$TAG="core-1.14.0"
207+
TAG="core-1.16.0"
208208
cosign verify-blob \
209209
--bundle OpenTelemetry.dll.sigstore.json \
210210
--certificate-identity "https://github.com/open-telemetry/opentelemetry-dotnet/.github/workflows/publish-packages-1.0.yml@refs/tags/$TAG" \
@@ -213,13 +213,16 @@ cosign verify-blob \
213213
OpenTelemetry.dll
214214
```
215215

216+
> [!NOTE]
217+
> A successful verification outputs `Verified OK`.
218+
216219
#### Versions 1.10.0 - 1.14.0-rc.1
217220

218221
These versions are using separate signature and certificate files format known
219222
from cosign 2.x.
220223

221224
```bash
222-
$TAG="core-1.12.0"
225+
TAG="core-1.12.0"
223226
cosign verify-blob \
224227
--signature OpenTelemetry.dll-keyless.sig \
225228
--certificate OpenTelemetry.dll-keyless.pem \

src/OpenTelemetry.Api/Context/Propagation/TraceStateUtils.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,15 @@ private static bool ValidateKey(ReadOnlySpan<char> key)
219219

220220
[MethodImpl(MethodImplOptions.AggressiveInlining)]
221221
static bool IsValidFirstCharacter(char c)
222-
=> char.IsAsciiLetterLower(c) || char.IsAsciiDigit(c);
222+
{
223+
return char.IsAsciiLetterLower(c) || char.IsAsciiDigit(c);
224+
}
223225

224226
[MethodImpl(MethodImplOptions.AggressiveInlining)]
225227
static bool IsValidCharacter(char c)
226-
=> IsValidFirstCharacter(c) || c is '_' or '-' or '*' or '/' or '@';
228+
{
229+
return IsValidFirstCharacter(c) || c is '_' or '-' or '*' or '/' or '@';
230+
}
227231
}
228232

229233
private static bool ValidateValue(ReadOnlySpan<char> value)

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Serializer/ProtobufOtlpMetricSerializer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ internal static class ProtobufOtlpMetricSerializer
1212
private const int ReserveSizeForLength = 4;
1313
private const int TraceIdSize = 16;
1414
private const int SpanIdSize = 8;
15+
16+
#if NETFRAMEWORK || NETSTANDARD2_0
1517
private static readonly ConditionalWeakTable<Metric, byte[]> CachedMetricMetadata = new();
18+
#else
19+
private static readonly ConditionalWeakTable<Metric, byte[]> CachedMetricMetadata = [];
20+
#endif
1621

1722
[ThreadStatic]
1823
private static Stack<List<Metric>>? metricListPool;

src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusMetric.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ UpDownCounter becomes gauge
239239
EscapingScheme.AllowUtf8 => this.allowUtf8Names ??= BuildAllowUtf8Names(this.rawName, this.Unit, this.Type, this.disableTotalNameSuffixForCounters),
240240
EscapingScheme.Dots => this.dotsNames ??= BuildEscapedNames(this.rawName, this.Unit, this.Type, this.disableTotalNameSuffixForCounters, EscapingScheme.Dots),
241241
EscapingScheme.Values => this.valuesNames ??= BuildEscapedNames(this.rawName, this.Unit, this.Type, this.disableTotalNameSuffixForCounters, EscapingScheme.Values),
242-
_ => this.underscoreNames,
242+
EscapingScheme.Underscores or _ => this.underscoreNames,
243243
};
244244

245245
private static byte[] ConvertToBytes(string value)

src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/TextFormatSerializer.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ internal abstract class TextFormatSerializer
6060
private static readonly long UnixEpochTicks = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).Ticks;
6161
#endif
6262

63+
// Scope labels (otel_scope_*) depend only on the Metric's invariant
64+
// scope (meter name/version/schema-url/tags) and are not affected by
65+
// the negotiated escaping scheme, so the built label collections can
66+
// be computed once per Metric and reused across every serialization
67+
// call instead of being rebuilt for each call to WriteMetric.
68+
#if NET
69+
private static readonly ConditionalWeakTable<Metric, List<KeyValuePair<string, string>>> ScopeLabelsCache = [];
70+
private static readonly ConditionalWeakTable<Metric, List<LabelData>> ScopeLabelDataCache = [];
71+
#else
72+
private static readonly ConditionalWeakTable<Metric, List<KeyValuePair<string, string>>> ScopeLabelsCache = new();
73+
private static readonly ConditionalWeakTable<Metric, List<LabelData>> ScopeLabelDataCache = new();
74+
#endif
75+
6376
private static readonly string[] ReservedExemplarLabelNames = ["trace_id", "span_id"];
6477
private static readonly double[] ExactPowersOfTen =
6578
[
@@ -341,7 +354,7 @@ internal static int GetNextSerializedTagsBufferSize(int currentBufferSize)
341354
// the scrape immediately rather than repeatedly re-entering this allocation.
342355
var newBufferSize = currentBufferSize * 2;
343356

344-
return newBufferSize <= 0 || newBufferSize > MaxSerializedTagsBufferSize
357+
return newBufferSize is <= 0 or > MaxSerializedTagsBufferSize
345358
? throw new InvalidOperationException("The serialized Prometheus tag set exceeded the maximum supported size.")
346359
: newBufferSize;
347360
}
@@ -813,7 +826,7 @@ internal int WriteTags(
813826

814827
if (!options.SuppressScopeInfo)
815828
{
816-
foreach (var scopeLabel in CreateScopeLabelData(metric))
829+
foreach (var scopeLabel in GetScopeLabelData(metric))
817830
{
818831
// Scope labels (otel_scope_*) are already in their target Prometheus form, so they
819832
// are written verbatim and not re-escaped by the negotiated scheme, exactly as the
@@ -837,7 +850,7 @@ void WriteScopeLabels()
837850
// tags they can never collide with an already-written label. They only need to be
838851
// written (which also records their output keys so point tags can detect a collision
839852
// with a scope label).
840-
foreach (var scopeLabel in CreateScopeLabels(metric))
853+
foreach (var scopeLabel in GetScopeLabels(metric))
841854
{
842855
_ = TryWriteLabel(scopeLabel.Key, scopeLabel.Value, isScopeLabel: true);
843856
}
@@ -1290,12 +1303,15 @@ private static string NormalizeLabelKey(string value)
12901303
return builder.ToString();
12911304
}
12921305

1306+
private static List<KeyValuePair<string, string>> GetScopeLabels(Metric metric)
1307+
=> ScopeLabelsCache.GetValue(metric, CreateScopeLabels);
1308+
12931309
private static List<KeyValuePair<string, string>> CreateScopeLabels(Metric metric)
12941310
{
12951311
var orderedKeys = new List<string>();
12961312
var labelsByOutputKey = new Dictionary<string, List<LabelData>>(StringComparer.Ordinal);
12971313

1298-
foreach (var label in CreateScopeLabelData(metric))
1314+
foreach (var label in GetScopeLabelData(metric))
12991315
{
13001316
if (!labelsByOutputKey.TryGetValue(label.OutputKey, out var bucket))
13011317
{
@@ -1317,6 +1333,9 @@ private static List<KeyValuePair<string, string>> CreateScopeLabels(Metric metri
13171333
return scopeLabels;
13181334
}
13191335

1336+
private static List<LabelData> GetScopeLabelData(Metric metric)
1337+
=> ScopeLabelDataCache.GetValue(metric, CreateScopeLabelData);
1338+
13201339
private static List<LabelData> CreateScopeLabelData(Metric metric)
13211340
{
13221341
var scopeLabels = new List<LabelData>(3)
@@ -2105,7 +2124,7 @@ private int WriteOutputLabelKey(byte[] buffer, int cursor, string key)
21052124
EscapingScheme.AllowUtf8 => WriteLabelName(buffer, cursor, key),
21062125

21072126
// The dots and values schemes escape the name and quote it only if a colon survives.
2108-
_ => WriteEscapedLabelKey(buffer, cursor, key, this.Escaping),
2127+
EscapingScheme.Dots or EscapingScheme.Values or _ => WriteEscapedLabelKey(buffer, cursor, key, this.Escaping),
21092128
};
21102129
}
21112130

src/OpenTelemetry.Shims.OpenTracing/ScopeManagerShim.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ namespace OpenTelemetry.Shims.OpenTracing;
1010

1111
internal sealed class ScopeManagerShim : IScopeManager
1212
{
13-
#pragma warning disable IDE0028 // Simplify collection initialization
13+
#if NETFRAMEWORK || NETSTANDARD2_0
1414
private static readonly ConditionalWeakTable<TelemetrySpan, IScope> SpanScopeTable = new();
15-
#pragma warning restore IDE0028 // Simplify collection initialization
15+
#else
16+
private static readonly ConditionalWeakTable<TelemetrySpan, IScope> SpanScopeTable = [];
17+
#endif
1618

1719
#if DEBUG
1820
private int spanScopeTableCount;

src/OpenTelemetry/Metrics/MetricPoint/MetricPoint.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,9 @@ internal void TakeSnapshotWithExemplar(bool outputDelta)
902902
/// <returns><see langword="true"/> if there is unexported data; otherwise, <see langword="false"/>.</returns>
903903
internal bool HasUnexportedData()
904904
{
905+
#pragma warning disable IDE0066 // Convert switch statement to expression
905906
switch (this.aggType)
907+
#pragma warning restore IDE0066 // Convert switch statement to expression
906908
{
907909
case AggregationType.LongSumIncomingDelta:
908910
case AggregationType.LongSumIncomingCumulative:
@@ -918,6 +920,13 @@ internal bool HasUnexportedData()
918920
case AggregationType.DoubleGauge:
919921
return InterlockedHelper.Read(ref this.runningValue.AsDouble) != this.snapshotValue.AsDouble;
920922

923+
case AggregationType.Base2ExponentialHistogram:
924+
case AggregationType.Base2ExponentialHistogramWithMinMax:
925+
case AggregationType.Histogram:
926+
case AggregationType.HistogramWithBuckets:
927+
case AggregationType.HistogramWithMinMax:
928+
case AggregationType.HistogramWithMinMaxBuckets:
929+
case AggregationType.Invalid:
921930
default:
922931
// Histogram aggregations reset the running count to zero on each delta snapshot, so
923932
// a non-zero running count means measurements have been recorded since the last

test/Benchmarks/Exporter/ProtobufOtlpMetricSerializerBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void Setup()
5353

5454
this.meterProvider.ForceFlush();
5555

56-
this.capturedMetrics = collected.ToArray();
56+
this.capturedMetrics = [.. collected];
5757
this.batch = new Batch<Metric>(this.capturedMetrics, this.capturedMetrics.Length);
5858
}
5959

0 commit comments

Comments
 (0)