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

feat: add log correlation/injection #121

Merged
merged 14 commits into from
Jun 7, 2021
Merged

feat: add log correlation/injection #121

merged 14 commits into from
Jun 7, 2021

Conversation

seemk
Copy link
Contributor

@seemk seemk commented May 28, 2021

Description

Adds log injection support for bunyan, pino and winston. This option is disabled by default.

Not sure regarding the environment variable name, suggestions welcome.

Also fixed service name not being injected to provider resource.

Ticket ID: APMI-1628

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • Tested manually
  • Added automated tests

Checklist:

  • Changelogs have been updated
  • Unit tests have been added/updated
  • Documentation has been updated

@seemk seemk requested a review from owais as a code owner May 28, 2021 15:06
package.json Show resolved Hide resolved
src/instrumentations/index.ts Outdated Show resolved Hide resolved
}

const logHook = (_span: Span, record: LogRecord) => {
record['service'] = options.serviceName;
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason to not have this in the instrumentation packages? Otel spec recommends correlating with resources https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/overview.md#log-correlation

Copy link
Contributor Author

@seemk seemk Jun 3, 2021

Choose a reason for hiding this comment

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

AFAIK currently it's not possible to access the provider's resource information, or even reading span attributes; at least I haven't found any.

For reference:
https://open-telemetry.github.io/opentelemetry-js/interfaces/span.html
https://open-telemetry.github.io/opentelemetry-js/interfaces/tracerprovider.html

If that is the case I guess we need changes to the API to read this information, which might be useful for log correlation.

Edit: Taavo mentioned casting to BasicTracerProvider which the logger instrumentations could do, but not sure it can get through review at OTel. Might give it a try, but so long we can use this hook.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option is to allow passing a resource directly to the instrumentation constructor. Users can do it manually and our distributions can do it automatically. Issue with this is that a single node project might want to use two different resources to represent sub-components which wouldn't work in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated it to read from the SDK span resource attributes.

@codecov-commenter
Copy link

codecov-commenter commented Jun 3, 2021

Codecov Report

Merging #121 (db529b7) into main (63127ca) will increase coverage by 0.04%.
The diff coverage is 87.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #121      +/-   ##
==========================================
+ Coverage   85.77%   85.82%   +0.04%     
==========================================
  Files          11       12       +1     
  Lines         225      268      +43     
  Branches       46       61      +15     
==========================================
+ Hits          193      230      +37     
- Misses         32       38       +6     
Impacted Files Coverage Δ
src/instrumentations/index.ts 100.00% <ø> (ø)
src/instrumentations/logging.ts 77.77% <77.77%> (ø)
src/options.ts 98.33% <100.00%> (+0.25%) ⬆️
src/tracing.ts 97.61% <100.00%> (+0.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 63127ca...db529b7. Read the comment docs.

resource: new EnvResourceDetector().detect(),
resource: new EnvResourceDetector().detect().merge(
new Resource({
[ResourceAttributes.SERVICE_NAME]: options.serviceName,
Copy link
Contributor

Choose a reason for hiding this comment

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

If service name is not provided via options but is provided with OTEL_RESOURCE_ATTRIBUTES or OTEL_SERVICE_NAME in future, will it get ovewritten by the value of defaultServiceName here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The precedence is now options.serviceName > env.SPLUNK_SERVICE_NAME > service.name from env.OTEL_RESOURCE_ATTRIBUTES > defaultServiceName

@seemk seemk merged commit 470288d into main Jun 7, 2021
@seemk seemk deleted the log-inject branch June 7, 2021 13:48
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.

4 participants