-
Notifications
You must be signed in to change notification settings - Fork 855
[OTLP] Export LogRecord.CategoryName as InstrumentationScope name #4941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
9db7130
7fdeecb
221d29c
c92aa72
a233ea7
688b1cf
5630f11
b35f720
d7a8a37
d050875
e0ea045
a3d0424
264b513
7c2e9c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| // limitations under the License. | ||
| // </copyright> | ||
|
|
||
| using System.Collections.Concurrent; | ||
| using System.Runtime.CompilerServices; | ||
| using Google.Protobuf; | ||
| using OpenTelemetry.Internal; | ||
|
|
@@ -28,6 +29,8 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation; | |
|
|
||
| internal sealed class OtlpLogRecordTransformer | ||
| { | ||
| internal static readonly ConcurrentBag<OtlpLogs.ScopeLogs> LogListPool = new(); | ||
|
|
||
| private readonly SdkLimitOptions sdkLimitOptions; | ||
| private readonly ExperimentalOptions experimentalOptions; | ||
|
|
||
|
|
@@ -41,6 +44,9 @@ internal OtlpCollector.ExportLogsServiceRequest BuildExportRequest( | |
| OtlpResource.Resource processResource, | ||
| in Batch<LogRecord> logRecordBatch) | ||
| { | ||
| // https://github.com/open-telemetry/opentelemetry-dotnet/issues/4943 | ||
| Dictionary<string, OtlpLogs.ScopeLogs> logsByCategory = new Dictionary<string, OtlpLogs.ScopeLogs>(); | ||
|
|
||
| var request = new OtlpCollector.ExportLogsServiceRequest(); | ||
|
|
||
| var resourceLogs = new OtlpLogs.ResourceLogs | ||
|
|
@@ -49,21 +55,66 @@ internal OtlpCollector.ExportLogsServiceRequest BuildExportRequest( | |
| }; | ||
| request.ResourceLogs.Add(resourceLogs); | ||
|
|
||
| var scopeLogs = new OtlpLogs.ScopeLogs(); | ||
| resourceLogs.ScopeLogs.Add(scopeLogs); | ||
| logsByCategory.Clear(); | ||
vishweshbankwar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| foreach (var logRecord in logRecordBatch) | ||
| { | ||
| var otlpLogRecord = this.ToOtlpLog(logRecord); | ||
| if (otlpLogRecord != null) | ||
| { | ||
| if (!logsByCategory.TryGetValue(logRecord.CategoryName, out var scopeLogs)) | ||
| { | ||
| scopeLogs = this.GetLogListFromPool(logRecord.CategoryName); | ||
| logsByCategory.Add(logRecord.CategoryName, scopeLogs); | ||
| resourceLogs.ScopeLogs.Add(scopeLogs); | ||
| } | ||
|
|
||
| scopeLogs.LogRecords.Add(otlpLogRecord); | ||
| } | ||
| } | ||
|
|
||
| return request; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| internal void Return(OtlpCollector.ExportLogsServiceRequest request) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stay consistent with Traces and Metrics and change this to an extension method?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Planning on doing same refactor for traces and metrics. will remove the static classes. |
||
| { | ||
| var resourceLogs = request.ResourceLogs.FirstOrDefault(); | ||
| if (resourceLogs == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| foreach (var scope in resourceLogs.ScopeLogs) | ||
| { | ||
| scope.LogRecords.Clear(); | ||
| LogListPool.Add(scope); | ||
| } | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| internal OtlpLogs.ScopeLogs GetLogListFromPool(string name) | ||
| { | ||
| if (!LogListPool.TryTake(out var logs)) | ||
| { | ||
| logs = new OtlpLogs.ScopeLogs | ||
| { | ||
| Scope = new OtlpCommon.InstrumentationScope | ||
| { | ||
| Name = name, // Name is enforced to not be null, but it can be empty. | ||
| Version = string.Empty, // proto requires this to be non-null. | ||
| }, | ||
| }; | ||
| } | ||
| else | ||
| { | ||
| logs.Scope.Name = name; | ||
| logs.Scope.Version = string.Empty; | ||
| } | ||
|
|
||
| return logs; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| internal OtlpLogs.LogRecord ToOtlpLog(LogRecord logRecord) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.