-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into juan-fernandez/fix-shard-instrumentation
- Loading branch information
Showing
12 changed files
with
301 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/dd-trace/src/profiling/profilers/event_plugins/dns.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const EventPlugin = require('./event') | ||
|
||
class DNSPlugin extends EventPlugin { | ||
static get id () { | ||
return 'dns' | ||
} | ||
|
||
static get entryType () { | ||
return 'dns' | ||
} | ||
} | ||
|
||
module.exports = DNSPlugin |
16 changes: 16 additions & 0 deletions
16
packages/dd-trace/src/profiling/profilers/event_plugins/dns_lookup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const DNSPlugin = require('./dns') | ||
|
||
class DNSLookupPlugin extends DNSPlugin { | ||
static get operation () { | ||
return 'lookup' | ||
} | ||
|
||
extendEvent (event, startEvent) { | ||
event.name = 'lookup' | ||
event.detail = { hostname: startEvent[0] } | ||
|
||
return event | ||
} | ||
} | ||
|
||
module.exports = DNSLookupPlugin |
16 changes: 16 additions & 0 deletions
16
packages/dd-trace/src/profiling/profilers/event_plugins/dns_lookupservice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const DNSPlugin = require('./dns') | ||
|
||
class DNSLookupServicePlugin extends DNSPlugin { | ||
static get operation () { | ||
return 'lookup_service' | ||
} | ||
|
||
extendEvent (event, startEvent) { | ||
event.name = 'lookupService' | ||
event.detail = { host: startEvent[0], port: startEvent[1] } | ||
|
||
return event | ||
} | ||
} | ||
|
||
module.exports = DNSLookupServicePlugin |
24 changes: 24 additions & 0 deletions
24
packages/dd-trace/src/profiling/profilers/event_plugins/dns_resolve.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const DNSPlugin = require('./dns') | ||
|
||
const queryNames = new Map() | ||
|
||
class DNSResolvePlugin extends DNSPlugin { | ||
static get operation () { | ||
return 'resolve' | ||
} | ||
|
||
extendEvent (event, startEvent) { | ||
const rrtype = startEvent[1] | ||
let name = queryNames.get(rrtype) | ||
if (!name) { | ||
name = `query${rrtype}` | ||
queryNames.set(rrtype, name) | ||
} | ||
event.name = name | ||
event.detail = { host: startEvent[0] } | ||
|
||
return event | ||
} | ||
} | ||
|
||
module.exports = DNSResolvePlugin |
16 changes: 16 additions & 0 deletions
16
packages/dd-trace/src/profiling/profilers/event_plugins/dns_reverse.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const DNSPlugin = require('./dns') | ||
|
||
class DNSReversePlugin extends DNSPlugin { | ||
static get operation () { | ||
return 'reverse' | ||
} | ||
|
||
extendEvent (event, startEvent) { | ||
event.name = 'getHostByAddr' | ||
event.detail = { host: startEvent[0] } | ||
|
||
return event | ||
} | ||
} | ||
|
||
module.exports = DNSReversePlugin |
48 changes: 48 additions & 0 deletions
48
packages/dd-trace/src/profiling/profilers/event_plugins/event.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const { AsyncLocalStorage } = require('async_hooks') | ||
const TracingPlugin = require('../../../plugins/tracing') | ||
const { performance } = require('perf_hooks') | ||
|
||
// We are leveraging the TracingPlugin class for its functionality to bind | ||
// start/error/finish methods to the appropriate diagnostic channels. | ||
class EventPlugin extends TracingPlugin { | ||
constructor (eventHandler) { | ||
super() | ||
this.eventHandler = eventHandler | ||
this.store = new AsyncLocalStorage() | ||
this.entryType = this.constructor.entryType | ||
} | ||
|
||
start (startEvent) { | ||
this.store.enterWith({ | ||
startEvent, | ||
startTime: performance.now() | ||
}) | ||
} | ||
|
||
error () { | ||
this.store.getStore().error = true | ||
} | ||
|
||
finish () { | ||
const { startEvent, startTime, error } = this.store.getStore() | ||
if (error) { | ||
return // don't emit perf events for failed operations | ||
} | ||
const duration = performance.now() - startTime | ||
|
||
const context = this.activeSpan?.context() | ||
const _ddSpanId = context?.toSpanId() | ||
const _ddRootSpanId = context?._trace.started[0]?.context().toSpanId() || _ddSpanId | ||
|
||
const event = { | ||
entryType: this.entryType, | ||
startTime, | ||
duration, | ||
_ddSpanId, | ||
_ddRootSpanId | ||
} | ||
this.eventHandler(this.extendEvent(event, startEvent)) | ||
} | ||
} | ||
|
||
module.exports = EventPlugin |
24 changes: 24 additions & 0 deletions
24
packages/dd-trace/src/profiling/profilers/event_plugins/net.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const EventPlugin = require('./event') | ||
|
||
class NetPlugin extends EventPlugin { | ||
static get id () { | ||
return 'net' | ||
} | ||
|
||
static get operation () { | ||
return 'tcp' | ||
} | ||
|
||
static get entryType () { | ||
return 'net' | ||
} | ||
|
||
extendEvent (event, { options }) { | ||
event.name = 'connect' | ||
event.detail = options | ||
|
||
return event | ||
} | ||
} | ||
|
||
module.exports = NetPlugin |
Oops, something went wrong.