Skip to content

Commit

Permalink
Merge branch 'main' into eventcounters-stabilize
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla authored Oct 13, 2022
2 parents 71560ed + 3516028 commit 65521ee
Show file tree
Hide file tree
Showing 42 changed files with 1,323 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v3

- name: Setup .NET 6.0
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v3.0.1
with:
dotnet-version: 6.0.x

Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"fluentdData"
]
}
6 changes: 3 additions & 3 deletions build/Common.nonprod.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
Please sort alphabetically.
Refer to https://docs.microsoft.com/en-us/nuget/concepts/package-versioning for semver syntax.
-->
<BenchmarkDotNetPkgVer>[0.12.1,0.13)</BenchmarkDotNetPkgVer>
<BenchmarkDotNetPkgVer>[0.13.2,0.14)</BenchmarkDotNetPkgVer>
<CoverletCollectorPkgVer>[3.1.2,4.0.0)</CoverletCollectorPkgVer>
<DotNetXUnitCliVer>[2.3.1,3.0)</DotNetXUnitCliVer>
<MicrosoftExtensionsLoggingPkgVer>[5.0,6.0)</MicrosoftExtensionsLoggingPkgVer>
<MicrosoftExtensionsLoggingPkgVer>[5.0.0,7.0)</MicrosoftExtensionsLoggingPkgVer>
<MicrosoftNETTestSdkPkgVer>[16.11.0,17.0)</MicrosoftNETTestSdkPkgVer>
<MoqPkgVer>[4.17.2,5.0)</MoqPkgVer>
<OpenTelemetryExporterInMemoryPkgVer>$(OpenTelemetryPkgVer)</OpenTelemetryExporterInMemoryPkgVer>
<XUnitRunnerVisualStudioPkgVer>[2.4.3,3.0)</XUnitRunnerVisualStudioPkgVer>
<XUnitPkgVer>[2.4.1,3.0)</XUnitPkgVer>
<XUnitPkgVer>[2.4.2,3.0)</XUnitPkgVer>
</PropertyGroup>

</Project>
12 changes: 6 additions & 6 deletions build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
Please sort alphabetically.
Refer to https://docs.microsoft.com/en-us/nuget/concepts/package-versioning for semver syntax.
-->
<MinVerPkgVer>[2.4.0,3.0)</MinVerPkgVer>
<MinVerPkgVer>[4.2.0,5.0)</MinVerPkgVer>
<MicrosoftCodeAnalysisNetAnalyzersPkgVer>[6.0.0]</MicrosoftCodeAnalysisNetAnalyzersPkgVer>
<MicrosoftCodeCoveragePkgVer>[16.11.0]</MicrosoftCodeCoveragePkgVer>
<MicrosoftCodeCoveragePkgVer>[17.3.2]</MicrosoftCodeCoveragePkgVer>
<MicrosoftExtensionsHostingAbstractionsPkgVer>[2.1.0,5.0)</MicrosoftExtensionsHostingAbstractionsPkgVer>
<MicrosoftExtensionsOptionsPkgVer>[3.1.0,)</MicrosoftExtensionsOptionsPkgVer>
<MicrosoftNETFrameworkReferenceAssembliesPkgVer>[1.0.0,2.0)</MicrosoftNETFrameworkReferenceAssembliesPkgVer>
<MicrosoftNETFrameworkReferenceAssembliesPkgVer>[1.0.3,2.0)</MicrosoftNETFrameworkReferenceAssembliesPkgVer>
<MicrosoftOwinPkgVer>[4.2.2,5.0)</MicrosoftOwinPkgVer>
<MicrosoftPublicApiAnalyzersPkgVer>[3.3.2]</MicrosoftPublicApiAnalyzersPkgVer>
<MicrosoftSourceLinkGitHubPkgVer>[1.0.0,2.0)</MicrosoftSourceLinkGitHubPkgVer>
<MicrosoftPublicApiAnalyzersPkgVer>[3.3.3]</MicrosoftPublicApiAnalyzersPkgVer>
<MicrosoftSourceLinkGitHubPkgVer>[1.1.1,2.0)</MicrosoftSourceLinkGitHubPkgVer>
<OpenTelemetryApiPkgVer>[1.3.1,2.0)</OpenTelemetryApiPkgVer>
<OpenTelemetryPkgVer>$(OpenTelemetryApiPkgVer)</OpenTelemetryPkgVer>
<StackExchangeRedisPkgVer>[2.1.58,3.0)</StackExchangeRedisPkgVer>
<StyleCopAnalyzersPkgVer>[1.2.0-beta.354,2.0)</StyleCopAnalyzersPkgVer>
<StyleCopAnalyzersPkgVer>[1.2.0-beta.435,2.0)</StyleCopAnalyzersPkgVer>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'net6.0' and '$(TargetFramework)' != 'netstandard2.1'">
Expand Down
86 changes: 0 additions & 86 deletions src/OpenTelemetry.Exporter.Geneva/GenevaBaseExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,95 +14,9 @@
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;

namespace OpenTelemetry.Exporter.Geneva;

public abstract class GenevaBaseExporter<T> : BaseExporter<T>
where T : class
{
internal static readonly IReadOnlyDictionary<string, string> V21_PART_A_MAPPING = new Dictionary<string, string>
{
// Part A
[Schema.V21.PartA.IKey] = "env_iKey",
[Schema.V21.PartA.Name] = "env_name",
[Schema.V21.PartA.Ver] = "env_ver",
[Schema.V21.PartA.Time] = "env_time",
[Schema.V21.PartA.Cv] = "env_cv",
[Schema.V21.PartA.Epoch] = "env_epoch",
[Schema.V21.PartA.Flags] = "env_flags",
[Schema.V21.PartA.PopSample] = "env_popSample",
[Schema.V21.PartA.SeqNum] = "env_seqNum",

// Part A Application extension
[Schema.V21.PartA.Extensions.App.Id] = "env_appId",
[Schema.V21.PartA.Extensions.App.Ver] = "env_appVer",

// Part A Cloud extension
[Schema.V21.PartA.Extensions.Cloud.Environment] = "env_cloud_environment",
[Schema.V21.PartA.Extensions.Cloud.Location] = "env_cloud_location",
[Schema.V21.PartA.Extensions.Cloud.Name] = "env_cloud_name",
[Schema.V21.PartA.Extensions.Cloud.DeploymentUnit] = "env_cloud_deploymentUnit",
[Schema.V21.PartA.Extensions.Cloud.Role] = "env_cloud_role",
[Schema.V21.PartA.Extensions.Cloud.RoleInstance] = "env_cloud_roleInstance",
[Schema.V21.PartA.Extensions.Cloud.RoleVer] = "env_cloud_roleVer",
[Schema.V21.PartA.Extensions.Cloud.Ver] = "env_cloud_ver",

// Part A Os extension
[Schema.V21.PartA.Extensions.Os.Name] = "env_os",
[Schema.V21.PartA.Extensions.Os.Ver] = "env_osVer",
};

internal static readonly IReadOnlyDictionary<string, string> V40_PART_A_MAPPING = new Dictionary<string, string>
{
// Part A
[Schema.V40.PartA.IKey] = "env_iKey",
[Schema.V40.PartA.Name] = "env_name",
[Schema.V40.PartA.Ver] = "env_ver",
[Schema.V40.PartA.Time] = "env_time",

// Part A Application Extension
[Schema.V40.PartA.Extensions.App.Id] = "env_app_id",
[Schema.V40.PartA.Extensions.App.Ver] = "env_app_ver",

// Part A Cloud Extension
[Schema.V40.PartA.Extensions.Cloud.Role] = "env_cloud_role",
[Schema.V40.PartA.Extensions.Cloud.RoleInstance] = "env_cloud_roleInstance",
[Schema.V40.PartA.Extensions.Cloud.RoleVer] = "env_cloud_roleVer",

// Part A Os extension
[Schema.V40.PartA.Extensions.Os.Name] = "env_os_name",
[Schema.V40.PartA.Extensions.Os.Ver] = "env_os_ver",
};

internal static int AddPartAField(byte[] buffer, int cursor, string name, object value)
{
if (V40_PART_A_MAPPING.TryGetValue(name, out string replacementKey))
{
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, replacementKey);
}
else
{
cursor = MessagePackSerializer.SerializeUnicodeString(buffer, cursor, name);
}

cursor = MessagePackSerializer.Serialize(buffer, cursor, value);
return cursor;
}

internal static int AddPartAField(byte[] buffer, int cursor, string name, Span<byte> value)
{
if (V40_PART_A_MAPPING.TryGetValue(name, out string replacementKey))
{
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, replacementKey);
}
else
{
cursor = MessagePackSerializer.SerializeUnicodeString(buffer, cursor, name);
}

cursor = MessagePackSerializer.SerializeSpan(buffer, cursor, value);
return cursor;
}
}
73 changes: 73 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// <copyright file="GenevaLogExporter.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
using OpenTelemetry.Internal;
using OpenTelemetry.Logs;

namespace OpenTelemetry.Exporter.Geneva;

public class GenevaLogExporter : GenevaBaseExporter<LogRecord>
{
internal bool IsUsingUnixDomainSocket;

private bool isDisposed;

private delegate ExportResult ExportLogRecordFunc(in Batch<LogRecord> batch);

private readonly ExportLogRecordFunc exportLogRecord;

private readonly IDisposable exporter;

public GenevaLogExporter(GenevaExporterOptions options)
{
Guard.ThrowIfNull(options);
Guard.ThrowIfNullOrWhitespace(options.ConnectionString);

var msgPackExporter = new MsgPackLogExporter(options);
this.IsUsingUnixDomainSocket = msgPackExporter.IsUsingUnixDomainSocket;
this.exportLogRecord = (in Batch<LogRecord> batch) => msgPackExporter.Export(in batch);
this.exporter = msgPackExporter;
}

public override ExportResult Export(in Batch<LogRecord> batch)
{
return this.exportLogRecord(batch);
}

protected override void Dispose(bool disposing)
{
if (this.isDisposed)
{
return;
}

if (disposing)
{
try
{
this.exporter.Dispose();
}
catch (Exception ex)
{
ExporterEventSource.Log.ExporterException("GenevaLogExporter Dispose failed.", ex);
}
}

this.isDisposed = true;
base.Dispose(disposing);
}
}
73 changes: 73 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/GenevaTraceExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// <copyright file="GenevaTraceExporter.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
using System.Diagnostics;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Exporter.Geneva;

public class GenevaTraceExporter : GenevaBaseExporter<Activity>
{
internal readonly bool IsUsingUnixDomainSocket;

private bool isDisposed;

private delegate ExportResult ExportActivityFunc(in Batch<Activity> batch);

private readonly ExportActivityFunc exportActivity;

private readonly IDisposable exporter;

public GenevaTraceExporter(GenevaExporterOptions options)
{
Guard.ThrowIfNull(options);
Guard.ThrowIfNullOrWhitespace(options.ConnectionString);

var msgPackExporter = new MsgPackTraceExporter(options);
this.IsUsingUnixDomainSocket = msgPackExporter.IsUsingUnixDomainSocket;
this.exportActivity = (in Batch<Activity> batch) => msgPackExporter.Export(in batch);
this.exporter = msgPackExporter;
}

public override ExportResult Export(in Batch<Activity> batch)
{
return this.exportActivity(batch);
}

protected override void Dispose(bool disposing)
{
if (this.isDisposed)
{
return;
}

if (disposing)
{
try
{
this.exporter.Dispose();
}
catch (Exception ex)
{
ExporterEventSource.Log.ExporterException("GenevaTraceExporter Dispose failed.", ex);
}
}

this.isDisposed = true;
base.Dispose(disposing);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// <copyright file="MsgPackExporter.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
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>
{
// Part A
[Schema.V40.PartA.IKey] = "env_iKey",
[Schema.V40.PartA.Name] = "env_name",
[Schema.V40.PartA.Ver] = "env_ver",
[Schema.V40.PartA.Time] = "env_time",

// Part A Application Extension
[Schema.V40.PartA.Extensions.App.Id] = "env_app_id",
[Schema.V40.PartA.Extensions.App.Ver] = "env_app_ver",

// Part A Cloud Extension
[Schema.V40.PartA.Extensions.Cloud.Role] = "env_cloud_role",
[Schema.V40.PartA.Extensions.Cloud.RoleInstance] = "env_cloud_roleInstance",
[Schema.V40.PartA.Extensions.Cloud.RoleVer] = "env_cloud_roleVer",

// Part A Os extension
[Schema.V40.PartA.Extensions.Os.Name] = "env_os_name",
[Schema.V40.PartA.Extensions.Os.Ver] = "env_os_ver",
};

protected static int AddPartAField(byte[] buffer, int cursor, string name, object value)
{
if (V40_PART_A_MAPPING.TryGetValue(name, out string replacementKey))
{
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, replacementKey);
}
else
{
cursor = MessagePackSerializer.SerializeUnicodeString(buffer, cursor, name);
}

cursor = MessagePackSerializer.Serialize(buffer, cursor, value);
return cursor;
}

protected static int AddPartAField(byte[] buffer, int cursor, string name, Span<byte> value)
{
if (V40_PART_A_MAPPING.TryGetValue(name, out string replacementKey))
{
cursor = MessagePackSerializer.SerializeAsciiString(buffer, cursor, replacementKey);
}
else
{
cursor = MessagePackSerializer.SerializeUnicodeString(buffer, cursor, name);
}

cursor = MessagePackSerializer.SerializeSpan(buffer, cursor, value);
return cursor;
}
}
Loading

0 comments on commit 65521ee

Please sign in to comment.