MCPcopy Create free account
hub / github.com/simstudioai/sim / forwardToCollector

Function forwardToCollector

apps/sim/app/api/telemetry/route.ts:56–146  ·  view source on GitHub ↗

* Forwards telemetry data to OpenTelemetry collector

(data: Record<string, unknown>)

Source from the content-addressed store, hash-verified

54 * Forwards telemetry data to OpenTelemetry collector
55 */
56async function forwardToCollector(data: Record<string, unknown>): Promise<boolean> {
57 if (!data || typeof data !== 'object') {
58 logger.error('Invalid telemetry data format')
59 return false
60 }
61
62 const endpoint = env.TELEMETRY_ENDPOINT || 'https://telemetry.simstudio.ai/v1/traces'
63 const timeout = DEFAULT_TIMEOUT
64
65 try {
66 const timestamp = Date.now() * 1000000
67
68 const safeAttrs = createSafeAttributes(data)
69
70 const serviceAttrs = [
71 { key: 'service.name', value: { stringValue: 'sim-studio' } },
72 {
73 key: 'service.version',
74 value: { stringValue: '0.1.0' },
75 },
76 {
77 key: 'deployment.environment',
78 value: { stringValue: isProd ? 'production' : 'development' },
79 },
80 ]
81
82 const spanName =
83 data.category && data.action ? `${data.category}.${data.action}` : 'telemetry.event'
84
85 const payload = {
86 resourceSpans: [
87 {
88 resource: {
89 attributes: serviceAttrs,
90 },
91 instrumentationLibrarySpans: [
92 {
93 spans: [
94 {
95 name: spanName,
96 kind: 1,
97 startTimeUnixNano: timestamp,
98 endTimeUnixNano: timestamp + 1000000,
99 attributes: safeAttrs,
100 },
101 ],
102 },
103 ],
104 },
105 ],
106 }
107
108 const controller = new AbortController()
109 const timeoutId = setTimeout(() => controller.abort(), timeout)
110
111 try {
112 const options = {
113 method: 'POST',

Callers 1

route.tsFile · 0.85

Calls 3

createSafeAttributesFunction · 0.85
errorMethod · 0.80
abortMethod · 0.65

Tested by

no test coverage detected