Add optional datadog log ingest (#213)

This commit is contained in:
lukasIO 2024-03-14 10:24:20 +01:00 committed by GitHub
parent b0086eec03
commit 35f8a27715
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 53 additions and 4 deletions

View file

@ -10,5 +10,6 @@ LIVEKIT_URL=wss://my-livekit-project.livekit.cloud
## PUBLIC
NEXT_PUBLIC_LK_TOKEN_ENDPOINT=/api/token
NEXT_PUBLIC_SHOW_SETTINGS_MENU=true
# NEXT_PUBLIC_DATADOG_CLIENT_TOKEN=client-token
# NEXT_PUBLIC_DATADOG_SITE=datadog-site

View file

@ -1,7 +1,9 @@
import * as React from 'react';
import { useRoomContext } from '@livekit/components-react';
import { setLogLevel, getLogger, LogLevel, RemoteTrackPublication } from 'livekit-client';
import { setLogLevel, LogLevel, RemoteTrackPublication, setLogExtension } from 'livekit-client';
import { tinykeys } from 'tinykeys';
import { datadogLogs } from '@datadog/browser-logs';
import styles from '../styles/Debug.module.css';
export const useDebugMode = ({ logLevel }: { logLevel?: LogLevel }) => {
@ -9,8 +11,35 @@ export const useDebugMode = ({ logLevel }: { logLevel?: LogLevel }) => {
React.useEffect(() => {
setLogLevel(logLevel ?? 'debug');
// @ts-ignore
setLogLevel('debug', 'lk-e2ee');
if (process.env.NEXT_PUBLIC_DATADOG_CLIENT_TOKEN && process.env.NEXT_PUBLIC_DATADOG_SITE) {
console.log('setting up datadog logs');
datadogLogs.init({
clientToken: process.env.NEXT_PUBLIC_DATADOG_CLIENT_TOKEN,
site: process.env.NEXT_PUBLIC_DATADOG_SITE,
forwardErrorsToLogs: true,
sessionSampleRate: 100,
});
setLogExtension((level, msg, context) => {
switch (level) {
case LogLevel.debug:
datadogLogs.logger.debug(msg, context);
break;
case LogLevel.info:
datadogLogs.logger.info(msg, context);
break;
case LogLevel.warn:
datadogLogs.logger.warn(msg, context);
break;
case LogLevel.error:
datadogLogs.logger.error(msg, context);
break;
default:
break;
}
});
}
// @ts-expect-error
window.__lk_room = room;

View file

@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@datadog/browser-logs": "^5.10.0",
"@livekit/components-react": "2.0.3",
"@livekit/components-styles": "1.0.10",
"@livekit/krisp-noise-filter": "^0.1.3",

View file

@ -5,6 +5,9 @@ settings:
excludeLinksFromLockfile: false
dependencies:
'@datadog/browser-logs':
specifier: ^5.10.0
version: 5.11.0
'@livekit/components-react':
specifier: 2.0.3
version: 2.0.3(livekit-client@2.0.7)(react-dom@18.2.0)(react@18.2.0)(tslib@2.6.2)
@ -81,6 +84,21 @@ packages:
resolution: {integrity: sha512-i5GE2Dk5ekdlK1TR7SugY4LWRrKSfb5T1Qn4unpIMbfxoeGKERKQ59HG3iYewacGD10SR7UzevfPnh6my4tNmQ==}
dev: false
/@datadog/browser-core@5.11.0:
resolution: {integrity: sha512-s5ak4Wf0xrxtlyruYtHZELEil+6ido+Zb/owpaYYU4ca05BDo4slIS03ztRCTYBv1dWpKJ6QkedvfklgWWAn6Q==}
dev: false
/@datadog/browser-logs@5.11.0:
resolution: {integrity: sha512-EvyZcfFOlQpopBtUIKFzj9cXzKfrALmF3GXUFxV6VfuQ5ByHywYdkdlUs0xGGblHyzXlidA7YEwTJiBa6Hn38A==}
peerDependencies:
'@datadog/browser-rum': 5.11.0
peerDependenciesMeta:
'@datadog/browser-rum':
optional: true
dependencies:
'@datadog/browser-core': 5.11.0
dev: false
/@eslint-community/eslint-utils@4.4.0(eslint@8.57.0):
resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}