-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathproxy.js
More file actions
125 lines (103 loc) · 2.92 KB
/
proxy.js
File metadata and controls
125 lines (103 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'use strict'
const NoopAppsecSdk = require('../appsec/sdk/noop')
const NoopLLMObsSDK = require('../llmobs/noop')
const NoopFlaggingProvider = require('../openfeature/noop')
const NoopAIGuardSDK = require('../aiguard/noop')
const PublicSpan = require('../opentracing/public/span')
const { SVC_SRC_KEY } = require('../../src/constants')
const NoopDogStatsDClient = require('./dogstatsd')
const NoopTracer = require('./tracer')
const noop = new NoopTracer()
const noopAppsec = new NoopAppsecSdk()
const noopDogStatsDClient = new NoopDogStatsDClient()
const noopLLMObs = new NoopLLMObsSDK(noop)
const noopOpenFeatureProvider = new NoopFlaggingProvider()
const noopAIGuard = new NoopAIGuardSDK()
/** @type {import('../../src/index')} Proxy */
class NoopProxy {
constructor () {
this._tracer = noop
this.appsec = noopAppsec
this.dogstatsd = noopDogStatsDClient
this.llmobs = noopLLMObs
this.openfeature = noopOpenFeatureProvider
this.aiguard = noopAIGuard
this.setBaggageItem = (key, value) => {}
this.getBaggageItem = (key) => {}
this.getAllBaggageItems = () => {}
this.removeBaggageItem = (keyToRemove) => {}
this.removeAllBaggageItems = () => {}
}
init () {
return this
}
use () {
return this
}
profilerStarted () {
return Promise.resolve(false)
}
trace (name, options, fn) {
if (!fn) {
fn = options
options = {}
}
if (typeof fn !== 'function') return
options = options || {}
if (options.service || options?.tags?.service || options?.tags?.['service.name']) {
options.tags = {
...options.tags,
[SVC_SRC_KEY]: 'm',
}
}
return this._tracer.trace(name, options, fn)
}
wrap (name, options, fn) {
if (!fn) {
fn = options
options = {}
}
if (typeof fn !== 'function') return fn
options = options || {}
if (options.service || options?.tags?.service || options?.tags?.['service.name']) {
options.tags = {
...options.tags,
[SVC_SRC_KEY]: 'm',
}
}
return this._tracer.wrap(name, options, fn)
}
setUrl () {
this._tracer.setUrl.apply(this._tracer, arguments)
return this
}
startSpan (name, options) {
if (options?.tags?.service || options?.tags?.['service.name']) {
options.tags = {
...options.tags,
[SVC_SRC_KEY]: 'm',
}
}
return new PublicSpan(this._tracer.startSpan.apply(this._tracer, arguments))
}
inject () {
return this._tracer.inject.apply(this._tracer, arguments)
}
extract () {
return this._tracer.extract.apply(this._tracer, arguments)
}
scope () {
return this._tracer.scope.apply(this._tracer, arguments)
}
getRumData () {
return this._tracer.getRumData.apply(this._tracer, arguments)
}
setUser (user) {
this.appsec.setUser(user)
return this
}
get TracerProvider () {
return require('../opentelemetry/tracer_provider')
}
}
module.exports = NoopProxy