-
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.
[test visibility] Add dynamic instrumentation logs writer for test vi…
…sibility (#4821) * Apply suggestions from code review Co-authored-by: Nikita Tkachenko <121111529+nikita-tkachenko-datadog@users.noreply.github.com>
- Loading branch information
1 parent
a872175
commit 564795f
Showing
10 changed files
with
438 additions
and
4 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
53 changes: 53 additions & 0 deletions
53
packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.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,53 @@ | ||
'use strict' | ||
const request = require('../../../exporters/common/request') | ||
const log = require('../../../log') | ||
const { safeJSONStringify } = require('../../../exporters/common/util') | ||
const { JSONEncoder } = require('../../encode/json-encoder') | ||
|
||
const BaseWriter = require('../../../exporters/common/writer') | ||
|
||
// Writer used by the integration between Dynamic Instrumentation and Test Visibility | ||
// It is used to encode and send logs to both the logs intake directly and the | ||
// `/debugger/v1/input` endpoint in the agent, which is a proxy to the logs intake. | ||
class DynamicInstrumentationLogsWriter extends BaseWriter { | ||
constructor ({ url, timeout, isAgentProxy = false }) { | ||
super(...arguments) | ||
this._url = url | ||
this._encoder = new JSONEncoder() | ||
this._isAgentProxy = isAgentProxy | ||
this.timeout = timeout | ||
} | ||
|
||
_sendPayload (data, _, done) { | ||
const options = { | ||
path: '/api/v2/logs', | ||
method: 'POST', | ||
headers: { | ||
'dd-api-key': process.env.DATADOG_API_KEY || process.env.DD_API_KEY, | ||
'Content-Type': 'application/json' | ||
}, | ||
// TODO: what's a good value for timeout for the logs intake? | ||
timeout: this.timeout || 15000, | ||
url: this._url | ||
} | ||
|
||
if (this._isAgentProxy) { | ||
delete options.headers['dd-api-key'] | ||
options.path = '/debugger/v1/input' | ||
} | ||
|
||
log.debug(() => `Request to the logs intake: ${safeJSONStringify(options)}`) | ||
|
||
request(data, options, (err, res) => { | ||
if (err) { | ||
log.error(err) | ||
done() | ||
return | ||
} | ||
log.debug(`Response from the logs intake: ${res}`) | ||
done() | ||
}) | ||
} | ||
} | ||
|
||
module.exports = DynamicInstrumentationLogsWriter |
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
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
Oops, something went wrong.