MCPcopy Create free account
hub / github.com/Effect-TS/effect / w3c

Function w3c

packages/effect/src/unstable/http/HttpTraceContext.ts:136–160  ·  view source on GitHub ↗
(headers)

Source from the content-addressed store, hash-verified

134 * @since 4.0.0
135 */
136export const w3c: FromHeaders = (headers) => {
137 if (!(headers["traceparent"])) {
138 return Option.none()
139 }
140 const parts = headers["traceparent"].split("-")
141 if (parts.length !== 4) {
142 return Option.none()
143 }
144 const [version, traceId, spanId, flags] = parts
145 switch (version) {
146 case "00": {
147 if (w3cTraceId.test(traceId) === false || w3cSpanId.test(spanId) === false) {
148 return Option.none()
149 }
150 return Option.some(Tracer.externalSpan({
151 traceId,
152 spanId,
153 sampled: (parseInt(flags, 16) & 1) === 1
154 }))
155 }
156 default: {
157 return Option.none()
158 }
159 }
160}

Callers 1

fromHeadersFunction · 0.85

Calls 2

someMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected