Skip to content

Commit

Permalink
Merge branch 'main' into resource-detector-process
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Dec 20, 2023
2 parents 95dbe32 + dda7b82 commit 76eb0a7
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
// SPDX-License-Identifier: Apache-2.0

using System;
#if NET8_0_OR_GREATER
using System.Collections.Frozen;
#endif
using System.Collections.Generic;

namespace OpenTelemetry.Exporter.Geneva;

internal abstract class MsgPackExporter
{
internal static readonly IReadOnlyDictionary<string, string> V40_PART_A_MAPPING = new Dictionary<string, string>
internal static readonly IReadOnlyDictionary<string, string> PART_A_MAPPING_DICTIONARY = new Dictionary<string, string>
{
// Part A
[Schema.V40.PartA.IKey] = "env_iKey",
Expand All @@ -30,6 +33,12 @@ internal abstract class MsgPackExporter
[Schema.V40.PartA.Extensions.Os.Ver] = "env_os_ver",
};

#if NET8_0_OR_GREATER
internal static readonly IReadOnlyDictionary<string, string> V40_PART_A_MAPPING = PART_A_MAPPING_DICTIONARY.ToFrozenDictionary();
#else
internal static readonly IReadOnlyDictionary<string, string> V40_PART_A_MAPPING = PART_A_MAPPING_DICTIONARY;
#endif

protected static int AddPartAField(byte[] buffer, int cursor, string name, object value)
{
if (V40_PART_A_MAPPING.TryGetValue(name, out string replacementKey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

using System;
#if NET8_0_OR_GREATER
using System.Collections.Frozen;
#endif
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
Expand All @@ -25,8 +28,15 @@ internal sealed class MsgPackLogExporter : MsgPackExporter, IDisposable

private readonly bool m_shouldExportEventName;
private readonly TableNameSerializer m_tableNameSerializer;

#if NET8_0_OR_GREATER
private readonly FrozenSet<string> m_customFields;
private readonly FrozenDictionary<string, object> m_prepopulatedFields;
#else
private readonly HashSet<string> m_customFields;
private readonly Dictionary<string, object> m_prepopulatedFields;
#endif

private readonly ExceptionStackExportMode m_exportExceptionStack;
private readonly List<string> m_prepopulatedFieldKeys;
private readonly byte[] m_bufferEpilogue;
Expand Down Expand Up @@ -77,7 +87,11 @@ public MsgPackLogExporter(GenevaExporterOptions options)
this.m_prepopulatedFieldKeys.Add(kv.Key);
}

#if NET8_0_OR_GREATER
this.m_prepopulatedFields = tempPrepopulatedFields.ToFrozenDictionary(StringComparer.Ordinal);
#else
this.m_prepopulatedFields = tempPrepopulatedFields;
#endif
}

// TODO: Validate custom fields (reserved name? etc).
Expand All @@ -89,7 +103,11 @@ public MsgPackLogExporter(GenevaExporterOptions options)
customFields.Add(name);
}

#if NET8_0_OR_GREATER
this.m_customFields = customFields.ToFrozenSet(StringComparer.Ordinal);
#else
this.m_customFields = customFields;
#endif
}

var buffer = new byte[BUFFER_SIZE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

using System;
#if NET8_0_OR_GREATER
using System.Collections.Frozen;
#endif
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
Expand Down Expand Up @@ -67,7 +70,11 @@ public MsgPackTraceExporter(GenevaExporterOptions options)
dedicatedFields.Add(name);
}

#if NET8_0_OR_GREATER
this.m_customFields = customFields.ToFrozenSet(StringComparer.Ordinal);
#else
this.m_customFields = customFields;
#endif

foreach (var name in CS40_PART_B_MAPPING.Keys)
{
Expand All @@ -77,7 +84,11 @@ public MsgPackTraceExporter(GenevaExporterOptions options)
dedicatedFields.Add("otel.status_code");
dedicatedFields.Add("otel.status_description");

#if NET8_0_OR_GREATER
this.m_dedicatedFields = dedicatedFields.ToFrozenSet(StringComparer.Ordinal);
#else
this.m_dedicatedFields = dedicatedFields;
#endif
}

var buffer = new byte[BUFFER_SIZE];
Expand Down Expand Up @@ -392,7 +403,7 @@ public void Dispose()

private static readonly string INVALID_SPAN_ID = default(ActivitySpanId).ToHexString();

private static readonly Dictionary<string, string> CS40_PART_B_MAPPING = new Dictionary<string, string>
private static readonly Dictionary<string, string> CS40_PART_B_MAPPING_DICTIONARY = new()
{
["db.system"] = "dbSystem",
["db.name"] = "dbName",
Expand All @@ -410,6 +421,12 @@ public void Dispose()
["messaging.url"] = "messagingUrl",
};

#if NET8_0_OR_GREATER
private static readonly FrozenDictionary<string, string> CS40_PART_B_MAPPING = CS40_PART_B_MAPPING_DICTIONARY.ToFrozenDictionary();
#else
private static readonly Dictionary<string, string> CS40_PART_B_MAPPING = CS40_PART_B_MAPPING_DICTIONARY;
#endif

private readonly ThreadLocal<byte[]> m_buffer = new(() => null);

private readonly byte[] m_bufferPrologue;
Expand All @@ -424,9 +441,15 @@ public void Dispose()

private readonly IDataTransport m_dataTransport;

#if NET8_0_OR_GREATER
private readonly FrozenSet<string> m_customFields;

private readonly FrozenSet<string> m_dedicatedFields;
#else
private readonly HashSet<string> m_customFields;

private readonly HashSet<string> m_dedicatedFields;
#endif

private bool isDisposed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 1.7.0-beta.1

Released 2023-Dec-20

* Update `OpenTelemetry.Api` to `1.7.0`.
([#1486](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1486))

Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Instrumentation.AspNet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 1.7.0-beta.1

Released 2023-Dec-20

* Added enrich functionality to metric instrumentation
([#1407](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1407)).

Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Instrumentation.Hangfire/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Update `OpenTelemetry.Api.ProviderBuilderExtensions` to `1.7.0`.
* Update `OpenTelemetry.Api` to `1.7.0`.
([#1508](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1508))

## 1.6.0-beta.1

Released 2023-Dec-20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Hangfire.Core" Version="[1.7.0,1.9.0)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsOptionsPkgVer)" />
<PackageReference Include="OpenTelemetry.Api.ProviderBuilderExtensions" Version="[1.6.0,2.0)" />
<PackageReference Include="OpenTelemetry.Api.ProviderBuilderExtensions" Version="$(OpenTelemetryCoreLatestVersion)" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\Guard.cs" Link="Includes\Guard.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

using System;
#if NET8_0_OR_GREATER
using System.Collections.Frozen;
#endif
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -239,7 +242,11 @@ public void GenevaTraceExporter_Serialization_Success(bool hasTableNameMapping,
}

using var exporter = new MsgPackTraceExporter(exporterOptions);
#if NET8_0_OR_GREATER
var dedicatedFields = typeof(MsgPackTraceExporter).GetField("m_dedicatedFields", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(exporter) as FrozenSet<string>;
#else
var dedicatedFields = typeof(MsgPackTraceExporter).GetField("m_dedicatedFields", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(exporter) as HashSet<string>;
#endif
var CS40_PART_B_MAPPING = typeof(MsgPackTraceExporter).GetField("CS40_PART_B_MAPPING", BindingFlags.NonPublic | BindingFlags.Static).GetValue(exporter) as IReadOnlyDictionary<string, string>;
var m_buffer = typeof(MsgPackTraceExporter).GetField("m_buffer", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(exporter) as ThreadLocal<byte[]>;

Expand Down Expand Up @@ -563,7 +570,9 @@ private static string GetTestMethodName([CallerMemberName] string callingMethodN
return callingMethodName;
}

private void AssertFluentdForwardModeForActivity(GenevaExporterOptions exporterOptions, object fluentdData, Activity activity, IReadOnlyDictionary<string, string> CS40_PART_B_MAPPING, HashSet<string> dedicatedFields, Action<Dictionary<object, object>> customChecksForActivity)
#pragma warning disable CA1859 // Use concrete types when possible for improved performance
private void AssertFluentdForwardModeForActivity(GenevaExporterOptions exporterOptions, object fluentdData, Activity activity, IReadOnlyDictionary<string, string> CS40_PART_B_MAPPING, ISet<string> dedicatedFields, Action<Dictionary<object, object>> customChecksForActivity)
#pragma warning restore CA1859 // Use concrete types when possible for improved performance
{
/* Fluentd Forward Mode:
[
Expand Down

0 comments on commit 76eb0a7

Please sign in to comment.