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 emitted by LoggerProvider are missing the resource attributes #4645

Closed
harelmo-lumigo opened this issue Apr 18, 2024 · 5 comments · Fixed by #4646
Closed

Logs emitted by LoggerProvider are missing the resource attributes #4645

harelmo-lumigo opened this issue Apr 18, 2024 · 5 comments · Fixed by #4646
Labels
pkg:sdk-logs type:feature A feature with no sub-issues to address

Comments

@harelmo-lumigo
Copy link
Contributor

What happened?

Steps to Reproduce

Run the setup code attached

Expected Result

A log record emitted with the resource attributes

Actual Result

A log record without the resource attributes, e.g.:

{
  timestamp: 1713419980772000,
  traceId: undefined,
  spanId: undefined,
  traceFlags: undefined,
  severityText: undefined,
  severityNumber: undefined,
  body: undefined,
  attributes: {}
}

Additional Details

See code below.
This happens in both span context and where there's no active span recording.

OpenTelemetry Setup Code

const { Resource } = require('@opentelemetry/resources');
const { LoggerProvider, SimpleLogRecordProcessor, ConsoleLogRecordExporter } = require('@opentelemetry/sdk-logs');
const logsAPI = require('@opentelemetry/api-logs');

const resource = Resource.default().merge({ 'some-thing-about': 'the-resource' })
const loggerProvider = new LoggerProvider({ resource });
loggerProvider.addLogRecordProcessor(new SimpleLogRecordProcessor(new ConsoleLogRecordExporter()));

logsAPI.logs.setGlobalLoggerProvider(loggerProvider).getLogger().emit({ message: 'Hello, world!' });

package.json

{
  "name": "my-opentelemetry-project",
  "version": "1.0.0",
  "description": "A project using OpenTelemetry for logging",
  "main": "logging.js",
  "scripts": {
    "start": "node logging.js"
  },
  "dependencies": {
    "@opentelemetry/resources": "1.17.1",
    "@opentelemetry/sdk-logs": "0.50.0",
    "@opentelemetry/api-logs": "0.50.0"
  }
}

Relevant log output

{
  timestamp: 1713419980772000,
  traceId: undefined,
  spanId: undefined,
  traceFlags: undefined,
  severityText: undefined,
  severityNumber: undefined,
  body: undefined,
  attributes: {}
}
@harelmo-lumigo harelmo-lumigo added bug Something isn't working triage labels Apr 18, 2024
@pichlermarc
Copy link
Member

They're simply not added to the output of the console exporter, right?

@pichlermarc
Copy link
Member

From what I can see they're in the exported data but not logged via the console exporter.

@harelmo-lumigo
Copy link
Contributor Author

From what I can see they're in the exported data but not logged via the console exporter.

I see, my apologies for missing that.
Should it be classified as a ConsoleExporter bug in that case, or is it by design?

@pichlermarc
Copy link
Member

From what I can see they're in the exported data but not logged via the console exporter.

I see, my apologies for missing that. Should it be classified as a ConsoleExporter bug in that case, or is it by design?

No worries, this was by design. Though I can see that it's confusing when it's not there. I've run into that multiple times when trying to troubleshoot apps running in k8s that I couldn't see the resources in the console exporter when I enabled it.

For that reason I added logging the resource to the ConsoleSpanExporter (#4605 classified as a feature).

I'll re-classify this issue as a feature. If you want you can open a PR to make the same change for the console log exporter. 🙂

@harelmo-lumigo
Copy link
Contributor Author

If you want you can open a PR to make the same change for the console log exporter. 🙂

@pichlermarc #4646 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:sdk-logs type:feature A feature with no sub-issues to address
Projects
None yet
2 participants