-
Notifications
You must be signed in to change notification settings - Fork 854
Logs: Add LogRecordData #3378
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
Logs: Add LogRecordData #3378
Changes from 3 commits
75c8525
33e635f
b34e24b
65c1f27
0e48f44
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 |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| OpenTelemetry.Logs.LogRecord.CategoryName.set -> void | ||
| OpenTelemetry.Logs.LogRecord.EventId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.Exception.set -> void | ||
| OpenTelemetry.Logs.LogRecord.LogLevel.set -> void | ||
| OpenTelemetry.Logs.LogRecord.SpanId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.Timestamp.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceState.set -> void | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.ForceFlush(int timeoutMilliseconds = -1) -> bool | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider() -> void | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider(System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions!>! configure) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| OpenTelemetry.Logs.LogRecord.CategoryName.set -> void | ||
| OpenTelemetry.Logs.LogRecord.EventId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.Exception.set -> void | ||
| OpenTelemetry.Logs.LogRecord.LogLevel.set -> void | ||
| OpenTelemetry.Logs.LogRecord.SpanId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.Timestamp.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceState.set -> void | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.ForceFlush(int timeoutMilliseconds = -1) -> bool | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider() -> void | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider(System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions!>! configure) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| OpenTelemetry.Logs.LogRecord.CategoryName.set -> void | ||
| OpenTelemetry.Logs.LogRecord.EventId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.Exception.set -> void | ||
| OpenTelemetry.Logs.LogRecord.LogLevel.set -> void | ||
| OpenTelemetry.Logs.LogRecord.SpanId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.Timestamp.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceState.set -> void | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.ForceFlush(int timeoutMilliseconds = -1) -> bool | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider() -> void | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider(System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions!>! configure) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| OpenTelemetry.Logs.LogRecord.CategoryName.set -> void | ||
| OpenTelemetry.Logs.LogRecord.EventId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.Exception.set -> void | ||
| OpenTelemetry.Logs.LogRecord.LogLevel.set -> void | ||
| OpenTelemetry.Logs.LogRecord.SpanId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.Timestamp.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceFlags.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceId.set -> void | ||
| OpenTelemetry.Logs.LogRecord.TraceState.set -> void | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.ForceFlush(int timeoutMilliseconds = -1) -> bool | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider() -> void | ||
| OpenTelemetry.Logs.OpenTelemetryLoggerProvider.OpenTelemetryLoggerProvider(System.Action<OpenTelemetry.Logs.OpenTelemetryLoggerOptions!>! configure) -> void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // <copyright file="LogRecordData.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> | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace OpenTelemetry.Logs | ||
| { | ||
| /// <summary> | ||
| /// Stores details about a log message. | ||
| /// </summary> | ||
| internal struct LogRecordData | ||
| { | ||
| internal DateTime TimestampBacking = DateTime.UtcNow; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="LogRecordData"/> struct. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Note: The <see cref="Timestamp"/> property is initialized to <see | ||
| /// cref="DateTime.UtcNow"/> automatically. | ||
| /// </remarks> | ||
| /// <param name="activity">Optional <see cref="Activity"/> used to populate context fields.</param> | ||
| public LogRecordData(Activity? activity = null) | ||
| { | ||
| if (activity != null) | ||
|
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. Can the ctor here use the static 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. Good question! Sadly, no. This is a weird quick of public LogRecordData(Activity? activity = null)
{
ref LogRecordData instance = ref this; // Error CS0188 The 'this' object cannot be used before all of its fields have been assigned
SetActivityContext(ref instance, activity);
}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. i missed that this was a struct. thanks for the explanation! |
||
| { | ||
| this.TraceId = activity.TraceId; | ||
| this.SpanId = activity.SpanId; | ||
| this.TraceState = activity.TraceStateString; | ||
| this.TraceFlags = activity.ActivityTraceFlags; | ||
| } | ||
| else | ||
| { | ||
| this.TraceId = default; | ||
| this.SpanId = default; | ||
| this.TraceState = null; | ||
| this.TraceFlags = ActivityTraceFlags.None; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log timestamp. | ||
CodeBlanch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// </summary> | ||
| public DateTime Timestamp | ||
| { | ||
| readonly get => this.TimestampBacking; | ||
| set { this.TimestampBacking = value.Kind == DateTimeKind.Local ? value.ToUniversalTime() : value; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log <see cref="ActivityTraceId"/>. | ||
| /// </summary> | ||
| public ActivityTraceId TraceId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log <see cref="ActivitySpanId"/>. | ||
| /// </summary> | ||
| public ActivitySpanId SpanId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log <see cref="ActivityTraceFlags"/>. | ||
| /// </summary> | ||
| public ActivityTraceFlags TraceFlags { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log trace state. | ||
| /// </summary> | ||
| public string? TraceState { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log category name. | ||
| /// </summary> | ||
| public string? CategoryName { get; set; } = null; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log <see cref="Microsoft.Extensions.Logging.LogLevel"/>. | ||
| /// </summary> | ||
| public LogLevel LogLevel { get; set; } = LogLevel.Trace; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log <see cref="Microsoft.Extensions.Logging.EventId"/>. | ||
| /// </summary> | ||
| public EventId EventId { get; set; } = default; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log message. | ||
| /// </summary> | ||
| public string? Message { get; set; } = null; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the log <see cref="System.Exception"/>. | ||
| /// </summary> | ||
| public Exception? Exception { get; set; } = null; | ||
|
|
||
| internal static void SetActivityContext(ref LogRecordData data, Activity? activity = null) | ||
| { | ||
| if (activity != null) | ||
| { | ||
| data.TraceId = activity.TraceId; | ||
| data.SpanId = activity.SpanId; | ||
| data.TraceState = activity.TraceStateString; | ||
| data.TraceFlags = activity.ActivityTraceFlags; | ||
| } | ||
| else | ||
| { | ||
| data.TraceId = default; | ||
| data.SpanId = default; | ||
| data.TraceState = null; | ||
| data.TraceFlags = ActivityTraceFlags.None; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.