Skip to content
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-branch] More spec-compliant handling of InstrumentationScope #3762

Merged

Conversation

CodeBlanch
Copy link
Member

Changes

Previously we were setting event.domain on each LogRecord. The spec actually says it should be added to the InstrumentationScope associated with the Logger emitting the LogRecord.

@CodeBlanch CodeBlanch requested a review from a team October 12, 2022 23:33
@codecov
Copy link

codecov bot commented Oct 12, 2022

Codecov Report

Merging #3762 (f5cd3f1) into main-logs (7419668) will increase coverage by 0.40%.
The diff coverage is 95.91%.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##           main-logs    #3762      +/-   ##
=============================================
+ Coverage      86.99%   87.39%   +0.40%     
=============================================
  Files            299      299              
  Lines          10631    10670      +39     
=============================================
+ Hits            9248     9325      +77     
+ Misses          1383     1345      -38     
Impacted Files Coverage Δ
src/OpenTelemetry.Api/Logs/LoggerOptions.cs 83.33% <85.71%> (+10.60%) ⬆️
src/OpenTelemetry.Api/InstrumentationScope.cs 91.66% <100.00%> (+18.93%) ⬆️
...etryProtocol/Implementation/LogRecordExtensions.cs 90.99% <100.00%> (+3.78%) ⬆️
src/OpenTelemetry/Logs/LogRecord.cs 65.41% <100.00%> (+0.26%) ⬆️
src/OpenTelemetry/Logs/LoggerSdk.cs 97.43% <100.00%> (+57.43%) ⬆️
...tpListener/Internal/PrometheusCollectionManager.cs 75.82% <0.00%> (+2.19%) ⬆️
...emetry.Api/Internal/OpenTelemetryApiEventSource.cs 82.35% <0.00%> (+2.94%) ⬆️
...tation/OpenTelemetryProtocolExporterEventSource.cs 85.00% <0.00%> (+10.00%) ⬆️
... and 2 more

@@ -46,7 +46,7 @@ public override void EmitEvent(string name, in LogRecordData data, in LogRecordA
{
Guard.ThrowIfNullOrWhitespace(name);

string eventDomain = this.EnsureEventDomain();
this.EnsureEventDomain();
Copy link
Member

@alanwest alanwest Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine as a TODO to follow up on, but throwing here should probably be vetted with the spec. I think normally we'd not allow for exceptions in this circumstance. Spec says:

Events require the event.domain attribute. The API MUST not allow creating an Event if the Logger instance doesn't have event.domain scope attribute.

This statement should be clarified. This might be a scenario where the SDK should log, but not throw an exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed weird to me as well! I asked about it, here's the reply I got:

open-telemetry/opentelemetry-specification#2768 (comment)

I'll drop a comment with that link in there for now.

@@ -33,29 +33,73 @@ internal static class LogRecordExtensions
{
private static readonly string[] SeverityTextMapping = new string[]
{
null, "Trace", "Debug", "Information", "Warning", "Error", "Fatal",
"Trace", "Debug", "Information", "Warning", "Error", "Fatal",
Copy link
Member

@alanwest alanwest Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to come back to in another PR maybe...

I think these are somewhat inspired by a combination of ILogger and the LogRecord data model... but technically, I think SeverityText is supposed to be the name as it's known by the logging framework being used see: https://github.com/open-telemetry/opentelemetry-proto/blob/724e427879e3d2bae2edc0218fff06e37b9eb46e/opentelemetry/proto/logs/v1/logs.proto#L144-L146

The SeverityNumber (which I don't think we're using today) on the other hand is governed by the data model. But even then, each logging framework should probably optionally be responsible for defining any mapping from its severity levels to one of the normalized OTLP severity numbers. See https://github.com/open-telemetry/opentelemetry-proto/blob/724e427879e3d2bae2edc0218fff06e37b9eb46e/opentelemetry/proto/logs/v1/logs.proto#L140-L142

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow interesting! At the moment on this branch, you have to specify a spec value or null:

public LogRecordSeverity? Severity { get; set; } = null;

That makes it the appender's job to map to spec a la:

private static LogRecordSeverity ConvertEventLevelToLogLevel(EventLevel eventLevel)
{
return eventLevel switch
{
EventLevel.Informational => LogRecordSeverity.Information,
EventLevel.Warning => LogRecordSeverity.Warning,
EventLevel.Error => LogRecordSeverity.Error,
EventLevel.Critical => LogRecordSeverity.Fatal,
_ => LogRecordSeverity.Trace,
};
}

We'll have to make changes to support passing the raw original log level as a string in addition to the spec value. Is the raw non-normalized value useful? 🤣

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the raw non-normalized value useful?

Yea, hard to say, maybe?

If you've been using some logging framework for 30 years, you're probably pretty accustomed to its nomenclature and not so much OpenTelemetry's. So, I guess it might make analyzing logs more familiar to an end user like this?

Also see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitytext

Copy link
Member

@alanwest alanwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments, but I think they're things we can come back to.

@CodeBlanch CodeBlanch merged commit 5e908f2 into open-telemetry:main-logs Oct 17, 2022
@CodeBlanch CodeBlanch deleted the logs-instrumentationscope branch October 17, 2022 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants