UNPKG

3.35 kBTypeScriptView Raw
1import { Context } from '../context/types';
2/**
3 * Injects `Context` into and extracts it from carriers that travel
4 * in-band across process boundaries. Encoding is expected to conform to the
5 * HTTP Header Field semantics. Values are often encoded as RPC/HTTP request
6 * headers.
7 *
8 * The carrier of propagated data on both the client (injector) and server
9 * (extractor) side is usually an object such as http headers. Propagation is
10 * usually implemented via library-specific request interceptors, where the
11 * client-side injects values and the server-side extracts them.
12 */
13export interface TextMapPropagator<Carrier = any> {
14 /**
15 * Injects values from a given `Context` into a carrier.
16 *
17 * OpenTelemetry defines a common set of format values (TextMapPropagator),
18 * and each has an expected `carrier` type.
19 *
20 * @param context the Context from which to extract values to transmit over
21 * the wire.
22 * @param carrier the carrier of propagation fields, such as http request
23 * headers.
24 * @param setter an optional {@link TextMapSetter}. If undefined, values will be
25 * set by direct object assignment.
26 */
27 inject(context: Context, carrier: Carrier, setter: TextMapSetter<Carrier>): void;
28 /**
29 * Given a `Context` and a carrier, extract context values from a
30 * carrier and return a new context, created from the old context, with the
31 * extracted values.
32 *
33 * @param context the Context from which to extract values to transmit over
34 * the wire.
35 * @param carrier the carrier of propagation fields, such as http request
36 * headers.
37 * @param getter an optional {@link TextMapGetter}. If undefined, keys will be all
38 * own properties, and keys will be accessed by direct object access.
39 */
40 extract(context: Context, carrier: Carrier, getter: TextMapGetter<Carrier>): Context;
41 /**
42 * Return a list of all fields which may be used by the propagator.
43 */
44 fields(): string[];
45}
46/**
47 * A setter is specified by the caller to define a specific method
48 * to set key/value pairs on the carrier within a propagator.
49 */
50export interface TextMapSetter<Carrier = any> {
51 /**
52 * Callback used to set a key/value pair on an object.
53 *
54 * Should be called by the propagator each time a key/value pair
55 * should be set, and should set that key/value pair on the propagator.
56 *
57 * @param carrier object or class which carries key/value pairs
58 * @param key string key to modify
59 * @param value value to be set to the key on the carrier
60 */
61 set(carrier: Carrier, key: string, value: string): void;
62}
63/**
64 * A getter is specified by the caller to define a specific method
65 * to get the value of a key from a carrier.
66 */
67export interface TextMapGetter<Carrier = any> {
68 /**
69 * Get a list of all keys available on the carrier.
70 *
71 * @param carrier
72 */
73 keys(carrier: Carrier): string[];
74 /**
75 * Get the value of a specific key from the carrier.
76 *
77 * @param carrier
78 * @param key
79 */
80 get(carrier: Carrier, key: string): undefined | string | string[];
81}
82export declare const defaultTextMapGetter: TextMapGetter;
83export declare const defaultTextMapSetter: TextMapSetter;
84//# sourceMappingURL=TextMapPropagator.d.ts.map
\No newline at end of file