Skip to content

Update allowed values for config.logInjection #6092

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let promise: Promise<void>;
ddTrace.init();
tracer.init({
apmTracingEnabled: false,
logInjection: true,
logInjection: 'structured',
startupLogs: false,
env: 'test',
version: '1.0.0',
Expand Down
8 changes: 6 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,13 @@ declare namespace tracer {
/**
* Whether to enable trace ID injection in log records to be able to correlate
* traces with logs.
* @default false
* all: enable for both structured and unstructured logs
* structured: enable only for structured logs
* (same as 'all' since dd-trace does support log injection for unstructured logs)
* disabled: disable trace ID injection in all logs
* @default 'structured'
*/
logInjection?: boolean,
logInjection?: string,

/**
* Whether to enable startup logs.
Expand Down
10 changes: 9 additions & 1 deletion packages/dd-trace/src/plugins/log_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { LOG } = require('../../../../ext/formats')
const Plugin = require('./plugin')
const log = require('../log')
const { storage } = require('../../../datadog-core')

function messageProxy (message, holder) {
Expand Down Expand Up @@ -46,10 +47,17 @@ module.exports = class LogPlugin extends Plugin {
}

_isEnabled (config) {
return config.enabled && (config.logInjection === true || config.ciVisAgentlessLogSubmissionEnabled)
return config.enabled &&
(config.logInjection === 'all' || config.logInjection === true || config.ciVisAgentlessLogSubmissionEnabled)
}

configure (config) {
if (config.logInjection === true) {
log.warn('Boolean value for config.logInjection is deprecated. Use "all" or "structured" instead.')
}
if (config.logInjection === false) {
log.warn('Boolean value for config.logInjection is deprecated. Use "disabled" instead.')
}
Comment on lines +55 to +60
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to replace boolean values with equivalent string values as early as possible, e.g. here or whereever this method receives the config object? Then you wouldn't have to worry about boolean values anymore elsewhere in the code.

Copy link
Member

Choose a reason for hiding this comment

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

Definitely agree with @szegedi here, I don't see why a string should be enforced. If this really is something we want to enforce though, we need to put this behind a check for DD_MAJOR as it's a major change that will need to only be in the next major.

return super.configure({
...config,
enabled: this._isEnabled(config)
Expand Down
Loading