@google-cloud/pubsub 4.4.0 → 4.5.0-otel-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +3 -1
  2. package/build/protos/google/pubsub/v1/pubsub.proto +29 -1
  3. package/build/protos/google/pubsub/v1/schema.proto +1 -1
  4. package/build/protos/protos.d.ts +26 -1
  5. package/build/protos/protos.js +115 -1
  6. package/build/protos/protos.json +30 -1
  7. package/build/src/ack-metadata.js +2 -3
  8. package/build/src/ack-metadata.js.map +1 -1
  9. package/build/src/iam.d.ts +11 -3
  10. package/build/src/iam.js +12 -2
  11. package/build/src/iam.js.map +1 -1
  12. package/build/src/index.d.ts +2 -0
  13. package/build/src/index.js +5 -1
  14. package/build/src/index.js.map +1 -1
  15. package/build/src/lease-manager.d.ts +2 -3
  16. package/build/src/lease-manager.js +19 -3
  17. package/build/src/lease-manager.js.map +1 -1
  18. package/build/src/message-queues.d.ts +8 -4
  19. package/build/src/message-queues.js +17 -8
  20. package/build/src/message-queues.js.map +1 -1
  21. package/build/src/message-stream.d.ts +0 -1
  22. package/build/src/publisher/flow-publisher.js +5 -0
  23. package/build/src/publisher/flow-publisher.js.map +1 -1
  24. package/build/src/publisher/index.d.ts +3 -3
  25. package/build/src/publisher/index.js +24 -46
  26. package/build/src/publisher/index.js.map +1 -1
  27. package/build/src/publisher/message-batch.d.ts +7 -1
  28. package/build/src/publisher/message-batch.js +11 -1
  29. package/build/src/publisher/message-batch.js.map +1 -1
  30. package/build/src/publisher/message-queues.d.ts +0 -2
  31. package/build/src/publisher/message-queues.js +32 -6
  32. package/build/src/publisher/message-queues.js.map +1 -1
  33. package/build/src/publisher/pubsub-message.d.ts +36 -1
  34. package/build/src/publisher/pubsub-message.js +26 -2
  35. package/build/src/publisher/pubsub-message.js.map +1 -1
  36. package/build/src/pubsub.d.ts +5 -1
  37. package/build/src/pubsub.js +4 -14
  38. package/build/src/pubsub.js.map +1 -1
  39. package/build/src/subscriber.d.ts +72 -8
  40. package/build/src/subscriber.js +179 -51
  41. package/build/src/subscriber.js.map +1 -1
  42. package/build/src/subscription.d.ts +3 -3
  43. package/build/src/subscription.js +7 -4
  44. package/build/src/subscription.js.map +1 -1
  45. package/build/src/telemetry-tracing.d.ts +231 -0
  46. package/build/src/telemetry-tracing.js +623 -0
  47. package/build/src/telemetry-tracing.js.map +1 -0
  48. package/build/src/topic.d.ts +2 -2
  49. package/build/src/topic.js +8 -4
  50. package/build/src/topic.js.map +1 -1
  51. package/build/src/util.js +4 -4
  52. package/build/src/util.js.map +1 -1
  53. package/build/src/v1/publisher_client.d.ts +0 -1
  54. package/build/src/v1/schema_service_client.d.ts +0 -1
  55. package/build/src/v1/subscriber_client.d.ts +0 -1
  56. package/build/src/v1/subscriber_client.js +1 -2
  57. package/build/src/v1/subscriber_client.js.map +1 -1
  58. package/package.json +8 -7
  59. package/CHANGELOG.md +0 -1506
  60. package/build/src/opentelemetry-tracing.d.ts +0 -23
  61. package/build/src/opentelemetry-tracing.js +0 -42
  62. package/build/src/opentelemetry-tracing.js.map +0 -1
@@ -0,0 +1,231 @@
1
+ /*!
2
+ * Copyright 2020-2024 Google LLC
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { SpanContext, Span, SpanKind, TextMapGetter, TextMapSetter, Context } from '@opentelemetry/api';
16
+ import { Attributes, PubsubMessage } from './publisher/pubsub-message';
17
+ import { PublishOptions } from './publisher/index';
18
+ import { Duration } from './temporal';
19
+ export { Span };
20
+ /**
21
+ * Determination of the level of OTel support we're providing.
22
+ *
23
+ * @private
24
+ */
25
+ export declare enum OpenTelemetryLevel {
26
+ /**
27
+ * None: OTel support is not enabled because we found no trace provider, or
28
+ * the user has not enabled it.
29
+ */
30
+ None = 0,
31
+ /**
32
+ * Legacy: We found a trace provider, but the user also specified the old
33
+ * manual enable flag; this will trigger the legacy attribute being included.
34
+ * The modern propagation attribute will _also_ be included.
35
+ */
36
+ Legacy = 1,
37
+ /**
38
+ * Modern: We will only inject/extract the modern propagation attribute.
39
+ */
40
+ Modern = 2
41
+ }
42
+ /**
43
+ * Manually set the OpenTelemetry enabledness.
44
+ *
45
+ * @param enabled The enabled flag to use, to override any automated methods.
46
+ * @private
47
+ * @internal
48
+ */
49
+ export declare function setGloballyEnabled(enabled: boolean): void;
50
+ /**
51
+ * Tries to divine what sort of OpenTelemetry we're supporting. See the enum
52
+ * for the meaning of the values, and other notes.
53
+ *
54
+ * Legacy OTel is no longer officially supported, but we don't want to
55
+ * break anyone at a non-major.
56
+ *
57
+ * @private
58
+ */
59
+ export declare function isEnabled(publishSettings?: PublishOptions): OpenTelemetryLevel;
60
+ /**
61
+ * Our Carrier object for propagation is anything with an 'attributes'
62
+ * object, which is one of several possible Message classes. (They're
63
+ * different for publish and subscribe.)
64
+ *
65
+ * Also we add a parentSpan optional member for passing around the
66
+ * actual Span object within the client library. This can be a publish
67
+ * or subscriber span, depending on the context.
68
+ *
69
+ * @private
70
+ */
71
+ export interface MessageWithAttributes {
72
+ attributes?: Attributes | null | undefined;
73
+ parentSpan?: Span;
74
+ }
75
+ /**
76
+ * Implements common members for the TextMap getter and setter interfaces for Pub/Sub messages.
77
+ *
78
+ * @private
79
+ */
80
+ export declare class PubsubMessageGetSet {
81
+ static keyPrefix: string;
82
+ keys(carrier: MessageWithAttributes): string[];
83
+ protected attributeName(key: string): string;
84
+ }
85
+ /**
86
+ * Implements the TextMap getter interface for Pub/Sub messages.
87
+ *
88
+ * @private
89
+ */
90
+ export declare class PubsubMessageGet extends PubsubMessageGetSet implements TextMapGetter<MessageWithAttributes> {
91
+ get(carrier: MessageWithAttributes, key: string): string | string[] | undefined;
92
+ }
93
+ /**
94
+ * Implements the TextMap setter interface for Pub/Sub messages.
95
+ *
96
+ * @private
97
+ */
98
+ export declare class PubsubMessageSet extends PubsubMessageGetSet implements TextMapSetter<MessageWithAttributes> {
99
+ set(carrier: MessageWithAttributes, key: string, value: string): void;
100
+ }
101
+ /**
102
+ * The getter to use when calling extract() on a Pub/Sub message.
103
+ *
104
+ * @private
105
+ */
106
+ export declare const pubsubGetter: PubsubMessageGet;
107
+ /**
108
+ * The setter to use when calling inject() on a Pub/Sub message.
109
+ *
110
+ * @private
111
+ */
112
+ export declare const pubsubSetter: PubsubMessageSet;
113
+ /**
114
+ * Description of the data structure passed for span attributes.
115
+ *
116
+ * @private
117
+ */
118
+ export interface SpanAttributes {
119
+ [x: string]: string | number | boolean;
120
+ }
121
+ /**
122
+ * Converts a SpanContext to a full Context, as needed.
123
+ *
124
+ * @private
125
+ */
126
+ export declare function spanContextToContext(parent?: SpanContext): Context | undefined;
127
+ /**
128
+ * The modern propagation attribute name.
129
+ *
130
+ * Technically this is determined by the OpenTelemetry library, but
131
+ * in practice, it follows the W3C spec, so this should be the right
132
+ * one. The only thing we're using it for, anyway, is emptying user
133
+ * supplied attributes.
134
+ *
135
+ * @private
136
+ */
137
+ export declare const modernAttributeName = "googclient_traceparent";
138
+ /**
139
+ * The old legacy attribute name.
140
+ *
141
+ * @private
142
+ */
143
+ export declare const legacyAttributeName = "googclient_OpenTelemetrySpanContext";
144
+ export interface AttributeParams {
145
+ topicName?: string;
146
+ subName?: string;
147
+ projectId?: string;
148
+ topicId?: string;
149
+ subId?: string;
150
+ }
151
+ /**
152
+ * Break down the subscription's full name into its project and ID.
153
+ *
154
+ * @private
155
+ */
156
+ export declare function getSubscriptionInfo(fullName: string): AttributeParams;
157
+ /**
158
+ * Break down the subscription's full name into its project and ID.
159
+ *
160
+ * @private
161
+ */
162
+ export declare function getTopicInfo(fullName: string): AttributeParams;
163
+ export declare class PubsubSpans {
164
+ static createAttributes(params: AttributeParams, message?: PubsubMessage, caller?: string): SpanAttributes;
165
+ static createPublisherSpan(message: PubsubMessage, topicName: string, caller: string): Span | undefined;
166
+ static updatePublisherTopicName(span: Span, topicName: string): void;
167
+ static createReceiveSpan(message: PubsubMessage, subName: string, parent: Context | undefined, caller: string): Span | undefined;
168
+ static createChildSpan(name: string, message?: PubsubMessage, parentSpan?: Span, attributes?: SpanAttributes): Span | undefined;
169
+ static createPublishFlowSpan(message: PubsubMessage): Span | undefined;
170
+ static createPublishSchedulerSpan(message: PubsubMessage): Span | undefined;
171
+ static createPublishRpcSpan(messages: MessageWithAttributes[], topicName: string, caller: string): Span | undefined;
172
+ static createAckRpcSpan(messageSpans: (Span | undefined)[], subName: string, caller: string): Span | undefined;
173
+ static createModackRpcSpan(messageSpans: (Span | undefined)[], subName: string, type: 'modack' | 'nack', caller: string, deadline?: Duration, isInitial?: boolean): Span | undefined;
174
+ static createReceiveFlowSpan(message: MessageWithAttributes): Span | undefined;
175
+ static createReceiveSchedulerSpan(message: MessageWithAttributes): Span | undefined;
176
+ static createReceiveProcessSpan(message: MessageWithAttributes, subName: string): Span | undefined;
177
+ static setReceiveProcessResult(span: Span, isAck: boolean): void;
178
+ }
179
+ /**
180
+ * Creates and manipulates Pub/Sub-related events on spans.
181
+ */
182
+ export declare class PubsubEvents {
183
+ static addEvent(text: string, message: MessageWithAttributes, attributes?: Attributes): void;
184
+ static publishStart(message: MessageWithAttributes): void;
185
+ static publishEnd(message: MessageWithAttributes): void;
186
+ static ackStart(message: MessageWithAttributes): void;
187
+ static ackEnd(message: MessageWithAttributes): void;
188
+ static modackStart(message: MessageWithAttributes): void;
189
+ static modackEnd(message: MessageWithAttributes): void;
190
+ static nackStart(message: MessageWithAttributes): void;
191
+ static nackEnd(message: MessageWithAttributes): void;
192
+ static ackCalled(span: Span): void;
193
+ static nackCalled(span: Span): void;
194
+ static modAckCalled(span: Span, deadline: Duration): void;
195
+ static modAckStart(message: MessageWithAttributes, deadline: Duration, isInitial: boolean): void;
196
+ static modAckEnd(message: MessageWithAttributes): void;
197
+ static shutdown(message: MessageWithAttributes): void;
198
+ }
199
+ /**
200
+ * Injects the trace context into a Pub/Sub message (or other object with
201
+ * an 'attributes' object) for propagation.
202
+ *
203
+ * This is for the publish side.
204
+ *
205
+ * @private
206
+ */
207
+ export declare function injectSpan(span: Span, message: MessageWithAttributes, enabled: OpenTelemetryLevel): void;
208
+ /**
209
+ * Returns true if this message potentially contains a span context.
210
+ *
211
+ * @private
212
+ */
213
+ export declare function containsSpanContext(message: MessageWithAttributes): boolean;
214
+ /**
215
+ * Extracts the trace context from a Pub/Sub message (or other object with
216
+ * an 'attributes' object) from a propagation, for receive processing. If no
217
+ * context was present, create a new parent span.
218
+ *
219
+ * This is for the receive side.
220
+ *
221
+ * @private
222
+ */
223
+ export declare function extractSpan(message: MessageWithAttributes, subName: string, enabled: OpenTelemetryLevel): Span | undefined;
224
+ export declare const legacyExports: {
225
+ /**
226
+ * @deprecated
227
+ * Use the new telemetry functionality instead; see the updated OpenTelemetry
228
+ * sample for an example.
229
+ */
230
+ createSpan: (spanName: string, kind: SpanKind, attributes?: SpanAttributes, parent?: SpanContext) => Span;
231
+ };