-
Notifications
You must be signed in to change notification settings - Fork 12
[internal] Add submit log flag to forward logs to DD #185
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
Changes from all commits
1dd4928
3073991
7c3299e
4a9f806
640cdc2
fa44152
4dbc394
2a27847
5f63d08
27d4c05
d5e236e
305c823
aa60224
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2019-Present Datadog, Inc. | ||
|
|
||
| import { HOST_NAME } from '../constants'; | ||
| import type { GlobalData, DdLogOptions } from '../types'; | ||
|
|
||
| import { doRequest } from './request'; | ||
|
|
||
| export const INTAKE_PATH = 'v1/input/pub44d5f4eb86e1392037b7501f7adc540e'; | ||
| export const INTAKE_HOST = 'browser-http-intake.logs.datadoghq.com'; | ||
|
|
||
| export const getSendLog = | ||
| (data: GlobalData) => | ||
| ({ message, context }: DdLogOptions): Promise<void> => { | ||
| return doRequest({ | ||
| // Don't delay the build too much on error. | ||
| retries: 2, | ||
| minTimeout: 100, | ||
| url: `https://${INTAKE_HOST}/${INTAKE_PATH}`, | ||
| method: 'POST', | ||
| type: 'json', | ||
| getData: async () => { | ||
| const payload = { | ||
| ddsource: data.packageName || HOST_NAME, | ||
| message, | ||
| service: 'build-plugins', | ||
| team: 'language-foundations', | ||
| env: data.env, | ||
| version: data.version, | ||
| bundler: { | ||
| name: data.bundler.name, | ||
| version: data.bundler.version, | ||
| }, | ||
| metadata: data.metadata, | ||
| ...context, | ||
| }; | ||
| return { | ||
| data: JSON.stringify(payload), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }; | ||
| }, | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ This is used to aggregate all the plugins and expose them to the bundler. | |
| <!-- #toc --> | ||
| - [Internal Plugins](#internal-plugins) | ||
| - [Analytics](#analytics) | ||
| - [Async Queue](#async-queue) | ||
| - [Build Report](#build-report) | ||
| - [Bundler Report](#bundler-report) | ||
| - [Custom Hooks](#custom-hooks) | ||
|
|
@@ -35,11 +36,18 @@ Most of the time they will interact via the global context. | |
|
|
||
| > Send some analytics data to Datadog internally. | ||
| > <br/> | ||
| > It gives you acces to the `context.sendLog()` function. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we don't give access to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, we're still give access to the function, but it's not defined from there anymore. I forgot to document it from the |
||
| > Will send a log at the beginning of a build. | ||
|
|
||
| #### [📝 Full documentation ➡️](/packages/plugins/analytics#readme) | ||
|
|
||
|
|
||
| ### Async Queue | ||
|
|
||
| > An internal queue for async actions that we want to finish before quitting the build. | ||
|
|
||
| #### [📝 Full documentation ➡️](/packages/plugins/async-queue#readme) | ||
|
|
||
|
|
||
| ### Build Report | ||
|
|
||
| > This will populate `context.build` with a bunch of data coming from the build. | ||
|
|
@@ -271,7 +279,7 @@ type GlobalContext = { | |
| // The list of all the plugin instances that are currently running in the ecosystem. | ||
| plugins: Plugin[]; | ||
| // Send a log to Datadog. | ||
| sendLog: (message: string, context?: Record<string, string>) => Promise<void>; | ||
| sendLog: ({ message: string, context?: Record<string, string> }) => Promise<void>; | ||
| // The start time of the build. | ||
| start: number; | ||
| // The version of the plugin. | ||
|
|
@@ -281,7 +289,7 @@ type GlobalContext = { | |
|
|
||
| > [!NOTE] | ||
| > Some parts of the context are only available after certain hooks: | ||
| > - all the helper functions, `asyncHook`, `getLogger`, `hook`, `inject`, `sendLog`, are available in the `init` hook. | ||
| > - some helper functions, `asyncHook`, `hook`, `inject` and `queue` are available in the `init` hook. | ||
| > - `cwd` is available in the `cwd` hook. | ||
| > - `context.bundler.rawConfig` is available in the `bundlerReport` hook. | ||
| > - `context.build.*` is available in the `buildReport` hook. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.