Socket
Socket
Sign inDemoInstall

@codesee/trace-datadog-rum

Package Overview
Dependencies
Maintainers
9
Versions
617
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codesee/trace-datadog-rum - npm Package Compare versions

Comparing version 0.1.0 to 0.398.0

2

dist/dd-client-trace.d.ts
import { RumEvent } from "@datadog/browser-rum";
export declare function initCodeseeDDTrace({ clientToken, env, version, }: {
export declare function initCodeSeeDDTrace({ clientToken, env, version, }: {
clientToken: string;

@@ -4,0 +4,0 @@ env: string;

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var Environment,bunyan=require("bunyan");function __awaiter(e,c,a,s){return new(a=a||Promise)(function(t,n){function o(e){try{i(s.next(e))}catch(e){n(e)}}function r(e){try{i(s.throw(e))}catch(e){n(e)}}function i(e){var n;e.done?t(e.value):((n=e.value)instanceof a?n:new a(function(e){e(n)})).then(o,r)}i((s=s.apply(e,c||[])).next())})}!function(e){e.Development="development",e.Production="production"}(Environment=Environment||{});const developmentConfig={INGESTION_SERVICE:"http://localhost:",NODE_ENV:Environment.Development},environment=process.env.NODE_ENV||Environment.Development,defaultConfig={INGESTION_SERVICE:"https://in-datadog.codesee.io",LOG_LEVEL:process.env.LOG_LEVEL||"info",NODE_ENV:environment},configs={[Environment.Development]:developmentConfig,[Environment.Production]:defaultConfig},environmentConfig=configs[environment];var config=Object.assign(Object.assign({},defaultConfig),environmentConfig);const sendTimout=6e5,queueLimit=25;function doSendTraces(e,n,t){return __awaiter(this,void 0,void 0,function*(){0!==n.length&&(t.info("Sending client traces"),process.env.INGE&&fetch(`${config.INGESTION_SERVICE}/api/v1/client/traces`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+e},body:JSON.stringify(n)}).then(e=>{t.info(`Received ${e.status} from client trace fetch.`)}).catch(e=>{t.error("Error sending client trace.",e)}))})}function maybeSendTraces(e,n,t,o,r){return(n.length>=t||Date.now()-o>=sendTimout)&&(doSendTraces(e,n,r),!0)}function initCodeseeDDTrace({clientToken:i,env:c,version:a}){let s=[],d=Date.now();const u=bunyan.createLogger({name:"trace-datadog-rum",level:config.LOG_LEVEL});return document.onvisibilitychange=()=>{"hidden"===document.visibilityState&&doSendTraces(i,s,u)},n=>{var t;if("resource"===n.type){var o=n;if("fetch"===o.resource.type||"xhr"===o.resource.type){var r=null!==(t=o._dd.trace_id)&&void 0!==t?t:"0";let e=null!==(t=o.version)&&void 0!==t?t:a;e=e||"";n={traceID:r,startTime:n.date,endTime:n.date+o.resource.duration,spans:[{name:o.resource.type,resource:null!==(t=null===(t=o.resource.method)||void 0===t?void 0:t.toUpperCase())&&void 0!==t?t:"",traceID:r,spanID:null!==(r=o._dd.span_id)&&void 0!==r?r:"0",parentID:"0",start:n.date,duration:o.resource.duration,error:0,meta:{version:e.toString(),"span.kind":"client","http.method":null!==(r=null===(r=o.resource.method)||void 0===r?void 0:r.toUpperCase())&&void 0!==r?r:"","http.url":o.resource.url,"http.status_code":null!==(o=o.resource.status_code)&&void 0!==o?o:0,service:null!==(n=n.service)&&void 0!==n?n:"",env:c},type:"http"}]};return s.push(n),maybeSendTraces(i,s,queueLimit,d,u)&&(d=Date.now(),s=[]),!0}}}}exports.initCodeseeDDTrace=initCodeseeDDTrace;
"use strict";function __awaiter(e,c,a,d){return new(a=a||Promise)(function(t,n){function o(e){try{i(d.next(e))}catch(e){n(e)}}function r(e){try{i(d.throw(e))}catch(e){n(e)}}function i(e){var n;e.done?t(e.value):((n=e.value)instanceof a?n:new a(function(e){e(n)})).then(o,r)}i((d=d.apply(e,c||[])).next())})}var Environment;Object.defineProperty(exports,"__esModule",{value:!0}),function(e){e.Development="development",e.Production="production"}(Environment=Environment||{});const developmentConfig={INGESTION_SERVICE:"http://localhost:3867",NODE_ENV:Environment.Development},environment=process.env.NODE_ENV||Environment.Development,defaultConfig={INGESTION_SERVICE:"https://in-datadog.codesee.io",LOG_LEVEL:process.env.LOG_LEVEL||"info",NODE_ENV:environment},configs={[Environment.Development]:developmentConfig,[Environment.Production]:defaultConfig},environmentConfig=configs[environment];var config=Object.assign(Object.assign({},defaultConfig),environmentConfig);const sendTimout=6e5,queueLimit=25;function doSendTraces(e,n){return __awaiter(this,void 0,void 0,function*(){0!==n.length&&fetch(`${config.INGESTION_SERVICE}/api/v1/client/traces`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+e},body:JSON.stringify(n)}).then(e=>{console.info(`trace-datadog-rum: Received ${e.status} from client trace fetch.`)}).catch(e=>{console.error("trace-datadog-rum: Error sending client trace.",e)})})}function maybeSendTraces(e,n,t,o){return(n.length>=t||Date.now()-o>=sendTimout)&&(doSendTraces(e,n),!0)}function initCodeSeeDDTrace({clientToken:i,env:c,version:a}){let d=[],s=Date.now();return void 0!==document&&(document.onvisibilitychange=()=>{"hidden"===document.visibilityState&&doSendTraces(i,d)}),n=>{var t;if("resource"===n.type){var o=n;if("fetch"===o.resource.type||"xhr"===o.resource.type){var r=null!==(t=o._dd.trace_id)&&void 0!==t?t:"0";let e=null!==(t=o.version)&&void 0!==t?t:a;e=e||"";n={traceID:r,startTime:n.date,endTime:n.date+o.resource.duration,spans:[{name:o.resource.type,resource:null!==(t=null===(t=o.resource.method)||void 0===t?void 0:t.toUpperCase())&&void 0!==t?t:"",traceID:r,spanID:null!==(r=o._dd.span_id)&&void 0!==r?r:"0",parentID:"0",start:n.date,duration:o.resource.duration,error:0,meta:{version:e.toString(),"span.kind":"client","http.method":null!==(r=null===(r=o.resource.method)||void 0===r?void 0:r.toUpperCase())&&void 0!==r?r:"","http.url":o.resource.url,"http.status_code":null!==(o=o.resource.status_code)&&void 0!==o?o:0,service:null!==(n=n.service)&&void 0!==n?n:"",env:c},type:"http"}]};return d.push(n),maybeSendTraces(i,d,queueLimit,s)&&(s=Date.now(),d=[]),!0}}}}exports.initCodeSeeDDTrace=initCodeSeeDDTrace;
{
"name": "@codesee/trace-datadog-rum",
"version": "0.1.0",
"version": "0.398.0",
"description": "CodeSee datadog client side trace library",

@@ -18,8 +18,9 @@ "main": "dist/index.js",

"prettier": "@codesee/prettier-config",
"peerDependencies": {
"@datadog/browser-rum": "^2.8.1"
},
"devDependencies": {
"@codesee/prettier-config": "^0.386.0",
"@rollup/plugin-eslint": "^8.0.1",
"@types/express": "4.17.14",
"@types/jest": "^26.0.24",
"@types/node": "^16.3.1",
"@typescript-eslint/eslint-plugin": "^4.15.0",

@@ -34,5 +35,5 @@ "@typescript-eslint/parser": "^4.15.0",

"rollup": "^2.42.3",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-typescript2": "^0.30.0",
"rollup-plugin-uglify": "6.0.4",
"shimmer": "1.2.1",
"ts-jest": "<23.10.0",

@@ -54,2 +55,2 @@ "typescript": "^4.1.4"

"license": "UNLICENSED"
}
}

@@ -5,6 +5,8 @@ import typescript from "rollup-plugin-typescript2";

import pkg from "./package.json";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
export default {
input: "src/index.ts",
external: ["@datadog/browser-rum"],
output: {

@@ -15,2 +17,6 @@ file: pkg.main,

plugins: [
resolve({
preferBuiltins: false,
}),
commonjs(),
eslint({

@@ -17,0 +23,0 @@ useEslintrc: true,

import { Config, Environment } from "./types";
const developmentConfig: Partial<Config> = {
INGESTION_SERVICE: "http://localhost:",
INGESTION_SERVICE: "http://localhost:3867",
NODE_ENV: Environment.Development,

@@ -6,0 +6,0 @@ };

import { RumEvent, RumResourceEvent } from "@datadog/browser-rum";
import bunyan, { createLogger } from "bunyan";
import config from "./config";

@@ -34,4 +33,3 @@ //TODO: Ten minute timout. Should be moved to an env var somewhere

clientToken: string,
traceQueue: Array<ClientTrace>,
log: bunyan
traceQueue: Array<ClientTrace>
) {

@@ -42,18 +40,18 @@ if (traceQueue.length === 0) {

log.info("Sending client traces");
if (process.env.INGE)
fetch(`${config.INGESTION_SERVICE}/api/v1/client/traces`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + clientToken,
},
body: JSON.stringify(traceQueue),
fetch(`${config.INGESTION_SERVICE}/api/v1/client/traces`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + clientToken,
},
body: JSON.stringify(traceQueue),
})
.then((response) => {
console.info(
`trace-datadog-rum: Received ${response.status} from client trace fetch.`
);
})
.then((response) => {
log.info(`Received ${response.status} from client trace fetch.`);
})
.catch((error) => {
log.error("Error sending client trace.", error);
});
.catch((error) => {
console.error("trace-datadog-rum: Error sending client trace.", error);
});
}

@@ -65,7 +63,6 @@

queueLimit: number,
lastSend: number,
log: bunyan
lastSend: number
) {
if (traceQueue.length >= queueLimit || Date.now() - lastSend >= sendTimout) {
doSendTraces(clientToken, traceQueue, log);
doSendTraces(clientToken, traceQueue);
return true;

@@ -76,3 +73,3 @@ }

export function initCodeseeDDTrace({
export function initCodeSeeDDTrace({
clientToken,

@@ -90,13 +87,10 @@ env,

const log = createLogger({
name: "trace-datadog-rum",
level: config.LOG_LEVEL,
});
if (document !== undefined) {
document.onvisibilitychange = () => {
if (document.visibilityState === "hidden") {
doSendTraces(clientToken, traceQueue);
}
};
}
document.onvisibilitychange = () => {
if (document.visibilityState === "hidden") {
doSendTraces(clientToken, traceQueue, log);
}
};
return (event: RumEvent) => {

@@ -149,3 +143,3 @@ if (event.type !== "resource") {

if (maybeSendTraces(clientToken, traceQueue, queueLimit, lastSend, log)) {
if (maybeSendTraces(clientToken, traceQueue, queueLimit, lastSend)) {
lastSend = Date.now();

@@ -152,0 +146,0 @@ traceQueue = [];

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc