Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Oct 11, 2024
1 parent 2475c81 commit 8c937fc
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { getUserLandFrames } = require('../../../dd-trace/src/plugins/util/stacktrace')
const { getUserLandFrames } = require('../dd-trace/src/plugins/util/stacktrace')

const limit = Number(process.env._DD_CODE_ORIGIN_MAX_USER_FRAMES) || 8

Expand Down
23 changes: 0 additions & 23 deletions packages/datadog-plugin-code-origin/src/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
'use strict'

const { entryTag } = require('./lib/tags')
const CodeOriginForSpansPlugin = require('./index')
const { entryTag } = require('../../datadog-code-origin')
const Plugin = require('../../dd-trace/src/plugins/plugin')
const web = require('../../dd-trace/src/plugins/util/web')

const kCodeOriginForSpansTagsSym = Symbol('datadog.codeOriginForSpansTags')

class FastifyCodeOriginForSpansPlugin extends CodeOriginForSpansPlugin {
class FastifyCodeOriginForSpansPlugin extends Plugin {
static get id () {
return 'fastify-code-origin-for-spans'
return 'fastify'
}

instrument () {
constructor (...args) {
super(...args)

this.addSub('apm:fastify:request:handle', ({ req, routeConfig }) => {
const tags = routeConfig?.[kCodeOriginForSpansTagsSym]
if (!tags) return
Expand Down
8 changes: 4 additions & 4 deletions packages/datadog-plugin-fastify/src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'

const FastifyInstrumentationPlugin = require('./instrumentation')
const FastifyCodeOriginForSpansPlugin = require('../../datadog-plugin-code-origin/src/fastify')
const FastifyTracingPlugin = require('./tracing')
const FastifyCodeOriginForSpansPlugin = require('./code_origin')
const CompositePlugin = require('../../dd-trace/src/plugins/composite')

class FastifyPlugin extends CompositePlugin {
static get id () { return 'fastify' }
static get plugins () {
return {
instrumentation: FastifyInstrumentationPlugin,
codeOrigin: FastifyCodeOriginForSpansPlugin
tracing: FastifyTracingPlugin,
codeOriginForSpans: FastifyCodeOriginForSpansPlugin
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const RouterPlugin = require('../../datadog-plugin-router/src')

class FastifyInstrumentationPlugin extends RouterPlugin {
class FastifyTracingPlugin extends RouterPlugin {
static get id () {
return 'fastify'
}
Expand All @@ -16,4 +16,4 @@ class FastifyInstrumentationPlugin extends RouterPlugin {
}
}

module.exports = FastifyInstrumentationPlugin
module.exports = FastifyTracingPlugin
4 changes: 2 additions & 2 deletions packages/datadog-plugin-fastify/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,14 @@ describe('Plugin', () => {
}
})

describe('with tracer config codeOriginForSpansEnabled', () => {
describe('with tracer config codeOriginForSpans.enabled: true', () => {
if (semver.satisfies(specificVersion, '<4')) return // TODO: Why doesn't it work on older versions?

before(() => {
return agent.load(
['fastify', 'find-my-way', 'http'],
[{}, {}, { client: false }],
{ codeOriginForSpansEnabled: true }
{ codeOriginForSpans: { enabled: true } }
)
})

Expand Down
6 changes: 3 additions & 3 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class Config {
this._setValue(defaults, 'appsec.wafTimeout', 5e3) // µs
this._setValue(defaults, 'clientIpEnabled', false)
this._setValue(defaults, 'clientIpHeader', null)
this._setValue(defaults, 'codeOriginForSpansEnabled', false)
this._setValue(defaults, 'codeOriginForSpans.enabled', false)
this._setValue(defaults, 'dbmPropagationMode', 'disabled')
this._setValue(defaults, 'dogstatsd.hostname', '127.0.0.1')
this._setValue(defaults, 'dogstatsd.port', '8125')
Expand Down Expand Up @@ -704,7 +704,7 @@ class Config {
this._envUnprocessed['appsec.wafTimeout'] = DD_APPSEC_WAF_TIMEOUT
this._setBoolean(env, 'clientIpEnabled', DD_TRACE_CLIENT_IP_ENABLED)
this._setString(env, 'clientIpHeader', DD_TRACE_CLIENT_IP_HEADER)
this._setBoolean(env, 'codeOriginForSpansEnabled', DD_CODE_ORIGIN_FOR_SPANS_ENABLED)
this._setBoolean(env, 'codeOriginForSpans.enabled', DD_CODE_ORIGIN_FOR_SPANS_ENABLED)
this._setString(env, 'dbmPropagationMode', DD_DBM_PROPAGATION_MODE)
this._setString(env, 'dogstatsd.hostname', DD_DOGSTATSD_HOSTNAME)
this._setString(env, 'dogstatsd.port', DD_DOGSTATSD_PORT)
Expand Down Expand Up @@ -871,7 +871,7 @@ class Config {
this._optsUnprocessed['appsec.wafTimeout'] = options.appsec.wafTimeout
this._setBoolean(opts, 'clientIpEnabled', options.clientIpEnabled)
this._setString(opts, 'clientIpHeader', options.clientIpHeader)
this._setBoolean(opts, 'codeOriginForSpansEnabled', options.codeOriginForSpansEnabled)
this._setBoolean(opts, 'codeOriginForSpans.enabled', options.codeOriginForSpans?.enabled)
this._setString(opts, 'dbmPropagationMode', options.dbmPropagationMode)
if (options.dogstatsd) {
this._setString(opts, 'dogstatsd.hostname', options.dogstatsd.hostname)
Expand Down
22 changes: 13 additions & 9 deletions packages/dd-trace/test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe('Config', () => {
expect(config).to.have.property('reportHostname', false)
expect(config).to.have.property('scope', undefined)
expect(config).to.have.property('logLevel', 'debug')
expect(config).to.have.property('codeOriginForSpansEnabled', false)
expect(config).to.have.nested.property('codeOriginForSpans.enabled', false)
expect(config).to.have.property('dynamicInstrumentationEnabled', false)
expect(config).to.have.property('traceId128BitGenerationEnabled', true)
expect(config).to.have.property('traceId128BitLoggingEnabled', false)
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('Config', () => {
{ name: 'appsec.wafTimeout', value: 5e3, origin: 'default' },
{ name: 'clientIpEnabled', value: false, origin: 'default' },
{ name: 'clientIpHeader', value: null, origin: 'default' },
{ name: 'codeOriginForSpansEnabled', value: false, origin: 'default' },
{ name: 'codeOriginForSpans.enabled', value: false, origin: 'default' },
{ name: 'dbmPropagationMode', value: 'disabled', origin: 'default' },
{ name: 'dogstatsd.hostname', value: '127.0.0.1', origin: 'calculated' },
{ name: 'dogstatsd.port', value: '8125', origin: 'default' },
Expand Down Expand Up @@ -512,7 +512,7 @@ describe('Config', () => {
expect(config).to.have.property('clientIpHeader', 'x-true-client-ip')
expect(config).to.have.property('runtimeMetrics', true)
expect(config).to.have.property('reportHostname', true)
expect(config).to.have.property('codeOriginForSpansEnabled', true)
expect(config).to.have.nested.property('codeOriginForSpans.enabled', true)
expect(config).to.have.property('dynamicInstrumentationEnabled', true)
expect(config).to.have.property('env', 'test')
expect(config).to.have.property('sampleRate', 0.5)
Expand Down Expand Up @@ -608,7 +608,7 @@ describe('Config', () => {
{ name: 'appsec.wafTimeout', value: '42', origin: 'env_var' },
{ name: 'clientIpEnabled', value: true, origin: 'env_var' },
{ name: 'clientIpHeader', value: 'x-true-client-ip', origin: 'env_var' },
{ name: 'codeOriginForSpansEnabled', value: true, origin: 'env_var' },
{ name: 'codeOriginForSpans.enabled', value: true, origin: 'env_var' },
{ name: 'dogstatsd.hostname', value: 'dsd-agent', origin: 'env_var' },
{ name: 'dogstatsd.port', value: '5218', origin: 'env_var' },
{ name: 'dynamicInstrumentationEnabled', value: true, origin: 'env_var' },
Expand Down Expand Up @@ -738,7 +738,9 @@ describe('Config', () => {
env: 'test',
clientIpEnabled: true,
clientIpHeader: 'x-true-client-ip',
codeOriginForSpansEnabled: false,
codeOriginForSpans: {
enabled: false
},
sampleRate: 0.5,
rateLimit: 1000,
samplingRules,
Expand Down Expand Up @@ -826,7 +828,7 @@ describe('Config', () => {
expect(config).to.have.property('reportHostname', true)
expect(config).to.have.property('plugins', false)
expect(config).to.have.property('logLevel', logLevel)
expect(config).to.have.property('codeOriginForSpansEnabled', false)
expect(config).to.have.nested.property('codeOriginForSpans.enabled', false)
expect(config).to.have.property('traceId128BitGenerationEnabled', true)
expect(config).to.have.property('traceId128BitLoggingEnabled', true)
expect(config).to.have.property('spanRemoveIntegrationFromService', true)
Expand Down Expand Up @@ -881,7 +883,7 @@ describe('Config', () => {
{ name: 'appsec.standalone.enabled', value: true, origin: 'code' },
{ name: 'clientIpEnabled', value: true, origin: 'code' },
{ name: 'clientIpHeader', value: 'x-true-client-ip', origin: 'code' },
{ name: 'codeOriginForSpansEnabled', value: false, origin: 'code' },
{ name: 'codeOriginForSpans.enabled', value: false, origin: 'code' },
{ name: 'dogstatsd.hostname', value: 'agent-dsd', origin: 'code' },
{ name: 'dogstatsd.port', value: '5218', origin: 'code' },
{ name: 'dynamicInstrumentationEnabled', value: true, origin: 'code' },
Expand Down Expand Up @@ -1169,7 +1171,9 @@ describe('Config', () => {
remoteConfig: {
pollInterval: 42
},
codeOriginForSpansEnabled: false,
codeOriginForSpans: {
enabled: false
},
traceId128BitGenerationEnabled: false,
traceId128BitLoggingEnabled: false
})
Expand All @@ -1186,7 +1190,7 @@ describe('Config', () => {
expect(config).to.have.property('flushMinSpans', 500)
expect(config).to.have.property('service', 'test')
expect(config).to.have.property('version', '1.0.0')
expect(config).to.have.property('codeOriginForSpansEnabled', false)
expect(config).to.have.nested.property('codeOriginForSpans.enabled', false)
expect(config).to.have.property('dynamicInstrumentationEnabled', false)
expect(config).to.have.property('env', 'development')
expect(config).to.have.property('clientIpEnabled', true)
Expand Down

0 comments on commit 8c937fc

Please sign in to comment.