@google-cloud/pubsub 2.4.0 → 2.5.0
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.
- package/CHANGELOG.md +15 -0
- package/README.md +3 -0
- package/build/protos/google/pubsub/v1/pubsub.proto +50 -68
- package/build/src/opentelemetry-tracing.d.ts +30 -0
- package/build/src/opentelemetry-tracing.js +41 -0
- package/build/src/opentelemetry-tracing.js.map +1 -0
- package/build/src/publisher/index.d.ts +23 -0
- package/build/src/publisher/index.js +56 -2
- package/build/src/publisher/index.js.map +1 -1
- package/build/src/publisher/message-batch.d.ts +3 -3
- package/build/src/publisher/message-batch.js +3 -3
- package/build/src/pubsub.d.ts +14 -6
- package/build/src/pubsub.js +50 -15
- package/build/src/pubsub.js.map +1 -1
- package/build/src/subscriber.d.ts +9 -0
- package/build/src/subscriber.js +36 -0
- package/build/src/subscriber.js.map +1 -1
- package/build/src/v1/publisher_client.js +13 -14
- package/build/src/v1/publisher_client.js.map +1 -1
- package/build/src/v1/subscriber_client.js +34 -45
- package/build/src/v1/subscriber_client.js.map +1 -1
- package/package.json +9 -7
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
[1]: https://www.npmjs.com/package/@google-cloud/pubsub?activeTab=versions
|
|
6
6
|
|
|
7
|
+
## [2.5.0](https://www.github.com/googleapis/nodejs-pubsub/compare/v2.4.0...v2.5.0) (2020-08-17)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* Opentelemetry integration ([#1078](https://www.github.com/googleapis/nodejs-pubsub/issues/1078)) ([76db007](https://www.github.com/googleapis/nodejs-pubsub/commit/76db007f270a646e8570768fa827ea2a97b62cbc)), closes [#1066](https://www.github.com/googleapis/nodejs-pubsub/issues/1066) [#1070](https://www.github.com/googleapis/nodejs-pubsub/issues/1070)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* make request batching work again ([#1087](https://www.github.com/googleapis/nodejs-pubsub/issues/1087)) ([80e0ee3](https://www.github.com/googleapis/nodejs-pubsub/commit/80e0ee3a4ef0da325e61ce2b869f4c0f9829b136))
|
|
18
|
+
* properly handle non-emulator alternate endpoints for pub/sub ([#1060](https://www.github.com/googleapis/nodejs-pubsub/issues/1060)) ([195ebf6](https://www.github.com/googleapis/nodejs-pubsub/commit/195ebf648e00ba35f567cef06a06c31f3f9c57d9))
|
|
19
|
+
* **deps:** update opentelemetry monorepo to ^0.10.0 ([#1090](https://www.github.com/googleapis/nodejs-pubsub/issues/1090)) ([78a45ff](https://www.github.com/googleapis/nodejs-pubsub/commit/78a45ff1cb8fb921e5ca05e435554d684a777185))
|
|
20
|
+
* update minimum gax version to 2.7.0 to fix recent protobuf errors ([#1085](https://www.github.com/googleapis/nodejs-pubsub/issues/1085)) ([904348c](https://www.github.com/googleapis/nodejs-pubsub/commit/904348cd6471f267a54635fcd65fe4191896308e))
|
|
21
|
+
|
|
7
22
|
## [2.4.0](https://www.github.com/googleapis/nodejs-pubsub/compare/v2.3.0...v2.4.0) (2020-08-08)
|
|
8
23
|
|
|
9
24
|
|
package/README.md
CHANGED
|
@@ -22,6 +22,9 @@ For additional help developing Pub/Sub applications, in Node.js and other langua
|
|
|
22
22
|
guides.
|
|
23
23
|
|
|
24
24
|
|
|
25
|
+
A comprehensive list of changes in each version may be found in
|
|
26
|
+
[the CHANGELOG](https://github.com/googleapis/nodejs-pubsub/blob/master/CHANGELOG.md).
|
|
27
|
+
|
|
25
28
|
* [Google Cloud Pub/Sub Node.js Client API Reference][client-docs]
|
|
26
29
|
* [Google Cloud Pub/Sub Documentation][product-docs]
|
|
27
30
|
* [github.com/googleapis/nodejs-pubsub](https://github.com/googleapis/nodejs-pubsub)
|
|
@@ -42,9 +42,8 @@ service Publisher {
|
|
|
42
42
|
"https://www.googleapis.com/auth/cloud-platform,"
|
|
43
43
|
"https://www.googleapis.com/auth/pubsub";
|
|
44
44
|
|
|
45
|
-
// Creates the given topic with the given name. See the
|
|
46
|
-
//
|
|
47
|
-
// resource name rules</a>.
|
|
45
|
+
// Creates the given topic with the given name. See the [resource name rules](
|
|
46
|
+
// https://cloud.google.com/pubsub/docs/admin#resource_names).
|
|
48
47
|
rpc CreateTopic(Topic) returns (Topic) {
|
|
49
48
|
option (google.api.http) = {
|
|
50
49
|
put: "/v1/{name=projects/*/topics/*}"
|
|
@@ -98,11 +97,10 @@ service Publisher {
|
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
// Lists the names of the snapshots on this topic. Snapshots are used in
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
// captured by a snapshot.
|
|
100
|
+
// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
|
|
101
|
+
// which allow you to manage message acknowledgments in bulk. That is, you can
|
|
102
|
+
// set the acknowledgment state of messages in an existing subscription to the
|
|
103
|
+
// state captured by a snapshot.
|
|
106
104
|
rpc ListTopicSnapshots(ListTopicSnapshotsRequest)
|
|
107
105
|
returns (ListTopicSnapshotsResponse) {
|
|
108
106
|
option (google.api.http) = {
|
|
@@ -161,8 +159,8 @@ message Topic {
|
|
|
161
159
|
// must not start with `"goog"`.
|
|
162
160
|
string name = 1 [(google.api.field_behavior) = REQUIRED];
|
|
163
161
|
|
|
164
|
-
// See
|
|
165
|
-
//
|
|
162
|
+
// See [Creating and managing labels]
|
|
163
|
+
// (https://cloud.google.com/pubsub/docs/labels).
|
|
166
164
|
map<string, string> labels = 2;
|
|
167
165
|
|
|
168
166
|
// Policy constraining the set of Google Cloud Platform regions where messages
|
|
@@ -180,11 +178,11 @@ message Topic {
|
|
|
180
178
|
// A message that is published by publishers and consumed by subscribers. The
|
|
181
179
|
// message must contain either a non-empty data field or at least one attribute.
|
|
182
180
|
// Note that client libraries represent this object differently
|
|
183
|
-
// depending on the language. See the corresponding
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
//
|
|
187
|
-
//
|
|
181
|
+
// depending on the language. See the corresponding [client library
|
|
182
|
+
// documentation](https://cloud.google.com/pubsub/docs/reference/libraries) for
|
|
183
|
+
// more information. See [quotas and limits]
|
|
184
|
+
// (https://cloud.google.com/pubsub/quotas) for more information about message
|
|
185
|
+
// limits.
|
|
188
186
|
message PubsubMessage {
|
|
189
187
|
// The message data field. If this field is empty, the message must contain
|
|
190
188
|
// at least one attribute.
|
|
@@ -212,9 +210,6 @@ message PubsubMessage {
|
|
|
212
210
|
// delivered to subscribers in the order in which they are received by the
|
|
213
211
|
// Pub/Sub system. All `PubsubMessage`s published in a given `PublishRequest`
|
|
214
212
|
// must specify the same `ordering_key` value.
|
|
215
|
-
// <b>EXPERIMENTAL:</b> This feature is part of a closed alpha release. This
|
|
216
|
-
// API might be changed in backward-incompatible ways and is not recommended
|
|
217
|
-
// for production use. It is not subject to any SLA or deprecation policy.
|
|
218
213
|
string ordering_key = 5;
|
|
219
214
|
}
|
|
220
215
|
|
|
@@ -388,19 +383,17 @@ service Subscriber {
|
|
|
388
383
|
"https://www.googleapis.com/auth/cloud-platform,"
|
|
389
384
|
"https://www.googleapis.com/auth/pubsub";
|
|
390
385
|
|
|
391
|
-
// Creates a subscription to a given topic. See the
|
|
392
|
-
//
|
|
393
|
-
// resource name rules</a>.
|
|
386
|
+
// Creates a subscription to a given topic. See the [resource name rules]
|
|
387
|
+
// (https://cloud.google.com/pubsub/docs/admin#resource_names).
|
|
394
388
|
// If the subscription already exists, returns `ALREADY_EXISTS`.
|
|
395
389
|
// If the corresponding topic doesn't exist, returns `NOT_FOUND`.
|
|
396
390
|
//
|
|
397
391
|
// If the name is not provided in the request, the server will assign a random
|
|
398
392
|
// name for this subscription on the same project as the topic, conforming
|
|
399
|
-
// to the
|
|
400
|
-
//
|
|
401
|
-
//
|
|
402
|
-
//
|
|
403
|
-
// for REST API requests, you must specify a name in the request.
|
|
393
|
+
// to the [resource name format]
|
|
394
|
+
// (https://cloud.google.com/pubsub/docs/admin#resource_names). The generated
|
|
395
|
+
// name is populated in the returned Subscription object. Note that for REST
|
|
396
|
+
// API requests, you must specify a name in the request.
|
|
404
397
|
rpc CreateSubscription(Subscription) returns (Subscription) {
|
|
405
398
|
option (google.api.http) = {
|
|
406
399
|
put: "/v1/{name=projects/*/subscriptions/*}"
|
|
@@ -528,12 +521,11 @@ service Subscriber {
|
|
|
528
521
|
option (google.api.method_signature) = "snapshot";
|
|
529
522
|
}
|
|
530
523
|
|
|
531
|
-
// Lists the existing snapshots. Snapshots are used in
|
|
532
|
-
//
|
|
533
|
-
//
|
|
534
|
-
//
|
|
535
|
-
//
|
|
536
|
-
// captured by a snapshot.
|
|
524
|
+
// Lists the existing snapshots. Snapshots are used in [Seek](
|
|
525
|
+
// https://cloud.google.com/pubsub/docs/replay-overview) operations, which
|
|
526
|
+
// allow you to manage message acknowledgments in bulk. That is, you can set
|
|
527
|
+
// the acknowledgment state of messages in an existing subscription to the
|
|
528
|
+
// state captured by a snapshot.
|
|
537
529
|
rpc ListSnapshots(ListSnapshotsRequest) returns (ListSnapshotsResponse) {
|
|
538
530
|
option (google.api.http) = {
|
|
539
531
|
get: "/v1/{project=projects/*}/snapshots"
|
|
@@ -542,21 +534,19 @@ service Subscriber {
|
|
|
542
534
|
}
|
|
543
535
|
|
|
544
536
|
// Creates a snapshot from the requested subscription. Snapshots are used in
|
|
545
|
-
//
|
|
546
|
-
//
|
|
547
|
-
//
|
|
548
|
-
//
|
|
549
|
-
//
|
|
550
|
-
// <br><br>If the snapshot already exists, returns `ALREADY_EXISTS`.
|
|
537
|
+
// [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations,
|
|
538
|
+
// which allow you to manage message acknowledgments in bulk. That is, you can
|
|
539
|
+
// set the acknowledgment state of messages in an existing subscription to the
|
|
540
|
+
// state captured by a snapshot.
|
|
541
|
+
// If the snapshot already exists, returns `ALREADY_EXISTS`.
|
|
551
542
|
// If the requested subscription doesn't exist, returns `NOT_FOUND`.
|
|
552
543
|
// If the backlog in the subscription is too old -- and the resulting snapshot
|
|
553
544
|
// would expire in less than 1 hour -- then `FAILED_PRECONDITION` is returned.
|
|
554
545
|
// See also the `Snapshot.expire_time` field. If the name is not provided in
|
|
555
546
|
// the request, the server will assign a random
|
|
556
547
|
// name for this snapshot on the same project as the subscription, conforming
|
|
557
|
-
// to the
|
|
558
|
-
//
|
|
559
|
-
// format](https://cloud.google.com/pubsub/docs/admin#resource_names). The
|
|
548
|
+
// to the [resource name format]
|
|
549
|
+
// (https://cloud.google.com/pubsub/docs/admin#resource_names). The
|
|
560
550
|
// generated name is populated in the returned Snapshot object. Note that for
|
|
561
551
|
// REST API requests, you must specify a name in the request.
|
|
562
552
|
rpc CreateSnapshot(CreateSnapshotRequest) returns (Snapshot) {
|
|
@@ -580,12 +570,11 @@ service Subscriber {
|
|
|
580
570
|
};
|
|
581
571
|
}
|
|
582
572
|
|
|
583
|
-
// Removes an existing snapshot. Snapshots are used in
|
|
584
|
-
//
|
|
585
|
-
//
|
|
586
|
-
//
|
|
587
|
-
//
|
|
588
|
-
// captured by a snapshot.<br><br>
|
|
573
|
+
// Removes an existing snapshot. Snapshots are used in [Seek]
|
|
574
|
+
// (https://cloud.google.com/pubsub/docs/replay-overview) operations, which
|
|
575
|
+
// allow you to manage message acknowledgments in bulk. That is, you can set
|
|
576
|
+
// the acknowledgment state of messages in an existing subscription to the
|
|
577
|
+
// state captured by a snapshot.
|
|
589
578
|
// When the snapshot is deleted, all messages retained in the snapshot
|
|
590
579
|
// are immediately dropped. After a snapshot is deleted, a new one may be
|
|
591
580
|
// created with the same name, but the new one has no association with the old
|
|
@@ -598,13 +587,12 @@ service Subscriber {
|
|
|
598
587
|
}
|
|
599
588
|
|
|
600
589
|
// Seeks an existing subscription to a point in time or to a given snapshot,
|
|
601
|
-
// whichever is provided in the request. Snapshots are used in
|
|
602
|
-
//
|
|
603
|
-
//
|
|
604
|
-
//
|
|
605
|
-
//
|
|
606
|
-
//
|
|
607
|
-
// must be on the same topic.
|
|
590
|
+
// whichever is provided in the request. Snapshots are used in [Seek](
|
|
591
|
+
// https://cloud.google.com/pubsub/docs/replay-overview) operations, which
|
|
592
|
+
// allow you to manage message acknowledgments in bulk. That is, you can set
|
|
593
|
+
// the acknowledgment state of messages in an existing subscription to the
|
|
594
|
+
// state captured by a snapshot. Note that both the subscription and the
|
|
595
|
+
// snapshot must be on the same topic.
|
|
608
596
|
rpc Seek(SeekRequest) returns (SeekResponse) {
|
|
609
597
|
option (google.api.http) = {
|
|
610
598
|
post: "/v1/{subscription=projects/*/subscriptions/*}:seek"
|
|
@@ -666,10 +654,8 @@ message Subscription {
|
|
|
666
654
|
// Indicates whether to retain acknowledged messages. If true, then
|
|
667
655
|
// messages are not expunged from the subscription's backlog, even if they are
|
|
668
656
|
// acknowledged, until they fall out of the `message_retention_duration`
|
|
669
|
-
// window. This must be true if you would like to
|
|
670
|
-
//
|
|
671
|
-
// href="https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time">
|
|
672
|
-
// Seek to a timestamp</a>.
|
|
657
|
+
// window. This must be true if you would like to [Seek to a timestamp]
|
|
658
|
+
// (https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time).
|
|
673
659
|
bool retain_acked_messages = 7;
|
|
674
660
|
|
|
675
661
|
// How long to retain unacknowledged messages in the subscription's backlog,
|
|
@@ -688,9 +674,6 @@ message Subscription {
|
|
|
688
674
|
// will be delivered to the subscribers in the order in which they
|
|
689
675
|
// are received by the Pub/Sub system. Otherwise, they may be delivered in
|
|
690
676
|
// any order.
|
|
691
|
-
// <b>EXPERIMENTAL:</b> This feature is part of a closed alpha release. This
|
|
692
|
-
// API might be changed in backward-incompatible ways and is not recommended
|
|
693
|
-
// for production use. It is not subject to any SLA or deprecation policy.
|
|
694
677
|
bool enable_message_ordering = 10;
|
|
695
678
|
|
|
696
679
|
// A policy that specifies the conditions for this subscription's expiration.
|
|
@@ -1186,11 +1169,10 @@ message UpdateSnapshotRequest {
|
|
|
1186
1169
|
}
|
|
1187
1170
|
|
|
1188
1171
|
// A snapshot resource. Snapshots are used in
|
|
1189
|
-
//
|
|
1190
|
-
// operations, which allow
|
|
1191
|
-
// you
|
|
1192
|
-
//
|
|
1193
|
-
// captured by a snapshot.
|
|
1172
|
+
// [Seek](https://cloud.google.com/pubsub/docs/replay-overview)
|
|
1173
|
+
// operations, which allow you to manage message acknowledgments in bulk. That
|
|
1174
|
+
// is, you can set the acknowledgment state of messages in an existing
|
|
1175
|
+
// subscription to the state captured by a snapshot.
|
|
1194
1176
|
message Snapshot {
|
|
1195
1177
|
option (google.api.resource) = {
|
|
1196
1178
|
type: "pubsub.googleapis.com/Snapshot"
|
|
@@ -1217,8 +1199,8 @@ message Snapshot {
|
|
|
1217
1199
|
// snapshot that would expire in less than 1 hour after creation.
|
|
1218
1200
|
google.protobuf.Timestamp expire_time = 3;
|
|
1219
1201
|
|
|
1220
|
-
// See
|
|
1221
|
-
//
|
|
1202
|
+
// See [Creating and managing labels]
|
|
1203
|
+
// (https://cloud.google.com/pubsub/docs/labels).
|
|
1222
1204
|
map<string, string> labels = 4;
|
|
1223
1205
|
}
|
|
1224
1206
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2020 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 { Attributes, SpanContext, Span } from '@opentelemetry/api';
|
|
16
|
+
/**
|
|
17
|
+
* Wrapper for creating OpenTelemetry Spans
|
|
18
|
+
*
|
|
19
|
+
* @class
|
|
20
|
+
*/
|
|
21
|
+
export declare class OpenTelemetryTracer {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new span with the given properties
|
|
24
|
+
*
|
|
25
|
+
* @param {string} spanName the name for the span
|
|
26
|
+
* @param {Attributes?} attributes an object containing the attributes to be set for the span
|
|
27
|
+
* @param {SpanContext?} parent the context of the parent span to link to the span
|
|
28
|
+
*/
|
|
29
|
+
createSpan(spanName: string, attributes?: Attributes, parent?: SpanContext): Span;
|
|
30
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright 2020 Google LLC
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.OpenTelemetryTracer = void 0;
|
|
18
|
+
const api_1 = require("@opentelemetry/api");
|
|
19
|
+
/**
|
|
20
|
+
* Wrapper for creating OpenTelemetry Spans
|
|
21
|
+
*
|
|
22
|
+
* @class
|
|
23
|
+
*/
|
|
24
|
+
class OpenTelemetryTracer {
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new span with the given properties
|
|
27
|
+
*
|
|
28
|
+
* @param {string} spanName the name for the span
|
|
29
|
+
* @param {Attributes?} attributes an object containing the attributes to be set for the span
|
|
30
|
+
* @param {SpanContext?} parent the context of the parent span to link to the span
|
|
31
|
+
*/
|
|
32
|
+
createSpan(spanName, attributes, parent) {
|
|
33
|
+
const tracerProvider = api_1.trace.getTracer('default');
|
|
34
|
+
return tracerProvider.startSpan(spanName, {
|
|
35
|
+
parent: parent,
|
|
36
|
+
attributes: attributes,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.OpenTelemetryTracer = OpenTelemetryTracer;
|
|
41
|
+
//# sourceMappingURL=opentelemetry-tracing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentelemetry-tracing.js","sourceRoot":"","sources":["../../src/opentelemetry-tracing.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,4CAAwE;AAGxE;;;;GAIG;AACH,MAAa,mBAAmB;IAC9B;;;;;;OAMG;IACH,UAAU,CACR,QAAgB,EAChB,UAAuB,EACvB,MAAoB;QAEpB,MAAM,cAAc,GAAW,WAAK,CAAC,SAAS,CAAC,SAAS,CAAW,CAAC;QACpE,OAAO,cAAc,CAAC,SAAS,CAAC,QAAQ,EAAE;YACxC,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,UAAU;SACvB,CAAC,CAAC;IACL,CAAC;CACF;AAnBD,kDAmBC"}
|
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
*/
|
|
16
16
|
/// <reference types="node" />
|
|
17
17
|
import { CallOptions } from 'google-gax';
|
|
18
|
+
import { Span } from '@opentelemetry/api';
|
|
18
19
|
import { BatchPublishOptions } from './message-batch';
|
|
19
20
|
import { Queue, OrderedQueue } from './message-queues';
|
|
20
21
|
import { Topic } from '../topic';
|
|
21
22
|
import { RequestCallback, EmptyCallback } from '../pubsub';
|
|
22
23
|
import { google } from '../../protos/protos';
|
|
24
|
+
import { OpenTelemetryTracer } from '../opentelemetry-tracing';
|
|
23
25
|
export declare type PubsubMessage = google.pubsub.v1.IPubsubMessage;
|
|
24
26
|
export interface Attributes {
|
|
25
27
|
[key: string]: string;
|
|
@@ -29,7 +31,19 @@ export interface PublishOptions {
|
|
|
29
31
|
batching?: BatchPublishOptions;
|
|
30
32
|
gaxOpts?: CallOptions;
|
|
31
33
|
messageOrdering?: boolean;
|
|
34
|
+
enableOpenTelemetryTracing?: boolean;
|
|
32
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* @typedef PublishOptions
|
|
38
|
+
* @property {BatchPublishOptions} [batching] The maximum number of bytes to
|
|
39
|
+
* buffer before sending a payload.
|
|
40
|
+
* @property {object} [gaxOpts] Request configuration options, outlined
|
|
41
|
+
* {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html|here.}
|
|
42
|
+
* @property {boolean} [messageOrdering] If true, messages published with the
|
|
43
|
+
* same order key in Message will be delivered to the subscribers in the order in which they
|
|
44
|
+
* are received by the Pub/Sub system. Otherwise, they may be delivered in
|
|
45
|
+
* any order.
|
|
46
|
+
*/
|
|
33
47
|
export declare const BATCH_LIMITS: BatchPublishOptions;
|
|
34
48
|
/**
|
|
35
49
|
* A Publisher object allows you to publish messages to a specific topic.
|
|
@@ -47,6 +61,7 @@ export declare class Publisher {
|
|
|
47
61
|
settings: PublishOptions;
|
|
48
62
|
queue: Queue;
|
|
49
63
|
orderedQueues: Map<string, OrderedQueue>;
|
|
64
|
+
tracing: OpenTelemetryTracer | undefined;
|
|
50
65
|
constructor(topic: Topic, options?: PublishOptions);
|
|
51
66
|
flush(): Promise<void>;
|
|
52
67
|
flush(callback: EmptyCallback): void;
|
|
@@ -82,4 +97,12 @@ export declare class Publisher {
|
|
|
82
97
|
* @param {PublishOptions} options The publisher options.
|
|
83
98
|
*/
|
|
84
99
|
setOptions(options?: PublishOptions): void;
|
|
100
|
+
/**
|
|
101
|
+
* Constructs an OpenTelemetry span
|
|
102
|
+
*
|
|
103
|
+
* @private
|
|
104
|
+
*
|
|
105
|
+
* @param {PubsubMessage} message The message to create a span for
|
|
106
|
+
*/
|
|
107
|
+
constructSpan(message: PubsubMessage): Span | undefined;
|
|
85
108
|
}
|
|
@@ -20,6 +20,18 @@ const promisify_1 = require("@google-cloud/promisify");
|
|
|
20
20
|
const extend = require("extend");
|
|
21
21
|
const message_queues_1 = require("./message-queues");
|
|
22
22
|
const default_options_1 = require("../default-options");
|
|
23
|
+
const opentelemetry_tracing_1 = require("../opentelemetry-tracing");
|
|
24
|
+
/**
|
|
25
|
+
* @typedef PublishOptions
|
|
26
|
+
* @property {BatchPublishOptions} [batching] The maximum number of bytes to
|
|
27
|
+
* buffer before sending a payload.
|
|
28
|
+
* @property {object} [gaxOpts] Request configuration options, outlined
|
|
29
|
+
* {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html|here.}
|
|
30
|
+
* @property {boolean} [messageOrdering] If true, messages published with the
|
|
31
|
+
* same order key in Message will be delivered to the subscribers in the order in which they
|
|
32
|
+
* are received by the Pub/Sub system. Otherwise, they may be delivered in
|
|
33
|
+
* any order.
|
|
34
|
+
*/
|
|
23
35
|
exports.BATCH_LIMITS = {
|
|
24
36
|
maxBytes: Math.pow(1024, 2) * 9,
|
|
25
37
|
maxMessages: 1000,
|
|
@@ -41,6 +53,10 @@ class Publisher {
|
|
|
41
53
|
this.topic = topic;
|
|
42
54
|
this.queue = new message_queues_1.Queue(this);
|
|
43
55
|
this.orderedQueues = new Map();
|
|
56
|
+
this.tracing =
|
|
57
|
+
this.settings && this.settings.enableOpenTelemetryTracing
|
|
58
|
+
? new opentelemetry_tracing_1.OpenTelemetryTracer()
|
|
59
|
+
: undefined;
|
|
44
60
|
}
|
|
45
61
|
/**
|
|
46
62
|
* Immediately sends all remaining queued data. This is mostly useful
|
|
@@ -105,8 +121,12 @@ class Publisher {
|
|
|
105
121
|
\nInvalid value of type "${typeof value}" provided for "${key}".`);
|
|
106
122
|
}
|
|
107
123
|
}
|
|
124
|
+
const span = this.constructSpan(message);
|
|
108
125
|
if (!message.orderingKey) {
|
|
109
126
|
this.queue.add(message, callback);
|
|
127
|
+
if (span) {
|
|
128
|
+
span.end();
|
|
129
|
+
}
|
|
110
130
|
return;
|
|
111
131
|
}
|
|
112
132
|
const key = message.orderingKey;
|
|
@@ -117,6 +137,9 @@ class Publisher {
|
|
|
117
137
|
}
|
|
118
138
|
const queue = this.orderedQueues.get(key);
|
|
119
139
|
queue.add(message, callback);
|
|
140
|
+
if (span) {
|
|
141
|
+
span.end();
|
|
142
|
+
}
|
|
120
143
|
}
|
|
121
144
|
/**
|
|
122
145
|
* Indicates to the publisher that it is safe to continue publishing for the
|
|
@@ -150,8 +173,12 @@ class Publisher {
|
|
|
150
173
|
gaxOpts: {
|
|
151
174
|
isBundling: false,
|
|
152
175
|
},
|
|
176
|
+
enableOpenTelemetryTracing: false,
|
|
153
177
|
};
|
|
154
|
-
const { batching, gaxOpts, messageOrdering } = extend(true, defaults, options);
|
|
178
|
+
const { batching, gaxOpts, messageOrdering, enableOpenTelemetryTracing, } = extend(true, defaults, options);
|
|
179
|
+
this.tracing = enableOpenTelemetryTracing
|
|
180
|
+
? new opentelemetry_tracing_1.OpenTelemetryTracer()
|
|
181
|
+
: undefined;
|
|
155
182
|
this.settings = {
|
|
156
183
|
batching: {
|
|
157
184
|
maxBytes: Math.min(batching.maxBytes, exports.BATCH_LIMITS.maxBytes),
|
|
@@ -160,12 +187,39 @@ class Publisher {
|
|
|
160
187
|
},
|
|
161
188
|
gaxOpts,
|
|
162
189
|
messageOrdering,
|
|
190
|
+
enableOpenTelemetryTracing,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Constructs an OpenTelemetry span
|
|
195
|
+
*
|
|
196
|
+
* @private
|
|
197
|
+
*
|
|
198
|
+
* @param {PubsubMessage} message The message to create a span for
|
|
199
|
+
*/
|
|
200
|
+
constructSpan(message) {
|
|
201
|
+
const spanAttributes = {
|
|
202
|
+
data: message.data,
|
|
163
203
|
};
|
|
204
|
+
const span = this.tracing
|
|
205
|
+
? this.tracing.createSpan(`${this.topic.name} publisher`, spanAttributes)
|
|
206
|
+
: undefined;
|
|
207
|
+
if (span) {
|
|
208
|
+
if (message.attributes &&
|
|
209
|
+
message.attributes['googclient_OpenTelemetrySpanContext']) {
|
|
210
|
+
console.warn('googclient_OpenTelemetrySpanContext key set as message attribute, but will be overridden.');
|
|
211
|
+
}
|
|
212
|
+
if (!message.attributes) {
|
|
213
|
+
message.attributes = {};
|
|
214
|
+
}
|
|
215
|
+
message.attributes['googclient_OpenTelemetrySpanContext'] = JSON.stringify(span.context());
|
|
216
|
+
}
|
|
217
|
+
return span;
|
|
164
218
|
}
|
|
165
219
|
}
|
|
166
220
|
exports.Publisher = Publisher;
|
|
167
221
|
promisify_1.promisifyAll(Publisher, {
|
|
168
222
|
singular: true,
|
|
169
|
-
exclude: ['publish', 'setOptions'],
|
|
223
|
+
exclude: ['publish', 'setOptions', 'constructSpan'],
|
|
170
224
|
});
|
|
171
225
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/publisher/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,uDAAgE;AAChE,iCAAiC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/publisher/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,uDAAgE;AAChE,iCAAiC;AAKjC,qDAAqD;AAIrD,wDAAkD;AAClD,oEAA6D;AAiB7D;;;;;;;;;;GAUG;AAEU,QAAA,YAAY,GAAwB;IAC/C,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC;IAC/B,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAa,SAAS;IAMpB,YAAY,KAAY,EAAE,OAAwB;QAChD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,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Y,CAAC,QAAS,CAAC;gBAC7D,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,oBAAY,CAAC,WAAY,CAAC;gBACtE,eAAe,EAAE,QAAQ,CAAC,eAAe;aAC1C;YACD,OAAO;YACP,eAAe;YACf,0BAA0B;SAC3B,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,aAAa,CAAC,OAAsB;QAClC,MAAM,cAAc,GAAG;YACrB,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB,CAAC;QACF,MAAM,IAAI,GAAqB,IAAI,CAAC,OAAO;YACzC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,YAAY,EAAE,cAAc,CAAC;YACzE,CAAC,CAAC,SAAS,CAAC;QACd,IAAI,IAAI,EAAE;YACR,IACE,OAAO,CAAC,UAAU;gBAClB,OAAO,CAAC,UAAU,CAAC,qCAAqC,CAAC,EACzD;gBACA,OAAO,CAAC,IAAI,CACV,2FAA2F,CAC5F,CAAC;aACH;YACD,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;gBACvB,OAAO,CAAC,UAAU,GAAG,EAAE,CAAC;aACzB;YACD,OAAO,CAAC,UAAU,CAChB,qCAAqC,CACtC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAxND,8BAwNC;AAED,wBAAY,CAAC,SAAS,EAAE;IACtB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,CAAC,SAAS,EAAE,YAAY,EAAE,eAAe,CAAC;CACpD,CAAC,CAAC"}
|
|
@@ -21,11 +21,11 @@ export interface BatchPublishOptions {
|
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* @typedef BatchPublishOptions
|
|
24
|
-
* @property {number} [maxBytes=1024
|
|
24
|
+
* @property {number} [maxBytes=1 * 1024 * 1024] The maximum number of bytes to
|
|
25
25
|
* buffer before sending a payload.
|
|
26
|
-
* @property {number} [maxMessages=
|
|
26
|
+
* @property {number} [maxMessages=100] The maximum number of messages to
|
|
27
27
|
* buffer before sending a payload.
|
|
28
|
-
* @property {number} [maxMilliseconds=
|
|
28
|
+
* @property {number} [maxMilliseconds=10] The maximum duration to wait before
|
|
29
29
|
* sending a payload.
|
|
30
30
|
*/
|
|
31
31
|
/**
|
|
@@ -19,11 +19,11 @@ exports.MessageBatch = void 0;
|
|
|
19
19
|
const _1 = require("./");
|
|
20
20
|
/**
|
|
21
21
|
* @typedef BatchPublishOptions
|
|
22
|
-
* @property {number} [maxBytes=1024
|
|
22
|
+
* @property {number} [maxBytes=1 * 1024 * 1024] The maximum number of bytes to
|
|
23
23
|
* buffer before sending a payload.
|
|
24
|
-
* @property {number} [maxMessages=
|
|
24
|
+
* @property {number} [maxMessages=100] The maximum number of messages to
|
|
25
25
|
* buffer before sending a payload.
|
|
26
|
-
* @property {number} [maxMilliseconds=
|
|
26
|
+
* @property {number} [maxMilliseconds=10] The maximum duration to wait before
|
|
27
27
|
* sending a payload.
|
|
28
28
|
*/
|
|
29
29
|
/**
|
package/build/src/pubsub.d.ts
CHANGED
|
@@ -97,9 +97,11 @@ interface GetClientCallback {
|
|
|
97
97
|
* JSON file, the `projectId` option above is not necessary. NOTE: .pem and
|
|
98
98
|
* .p12 require you to specify the `email` option as well.
|
|
99
99
|
* @property {string} [apiEndpoint] The `apiEndpoint` from options will set the
|
|
100
|
-
* host. If not set, the `PUBSUB_EMULATOR_HOST` environment variable from
|
|
101
|
-
*
|
|
102
|
-
* used
|
|
100
|
+
* host. If not set, the `PUBSUB_EMULATOR_HOST` environment variable from the
|
|
101
|
+
* gcloud SDK is honored. We also check the `CLOUD_API_ENDPOINT_OVERRIDES_PUBSUB`
|
|
102
|
+
* environment variable used by `gcloud alpha pubsub`. Otherwise the actual API
|
|
103
|
+
* endpoint will be used. Note that if the URL doesn't end in '.googleapis.com',
|
|
104
|
+
* we will assume that it's an emulator and disable strict SSL checks.
|
|
103
105
|
* @property {string} [email] Account email address. Required when using a .pem
|
|
104
106
|
* or .p12 keyFilename.
|
|
105
107
|
* @property {object} [credentials] Credentials object.
|
|
@@ -167,9 +169,14 @@ export declare class PubSub {
|
|
|
167
169
|
detachSubscription(name: string, gaxOpts: CallOptions, callback: DetachSubscriptionCallback): void;
|
|
168
170
|
/**
|
|
169
171
|
* Determine the appropriate endpoint to use for API requests, first trying
|
|
170
|
-
* the
|
|
171
|
-
*
|
|
172
|
-
*
|
|
172
|
+
* the `apiEndpoint` parameter. If that isn't set, we try the Pub/Sub emulator
|
|
173
|
+
* environment variable (PUBSUB_EMULATOR_HOST). If that is also null, we try
|
|
174
|
+
* the standard `gcloud alpha pubsub` environment variable
|
|
175
|
+
* (CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB). Otherwise the default production
|
|
176
|
+
* API is used.
|
|
177
|
+
*
|
|
178
|
+
* Note that if the URL doesn't end in '.googleapis.com', we will assume that
|
|
179
|
+
* it's an emulator and disable strict SSL checks.
|
|
173
180
|
*
|
|
174
181
|
* @private
|
|
175
182
|
*/
|
|
@@ -286,6 +293,7 @@ export declare class PubSub {
|
|
|
286
293
|
* @throws {Error} If a name is not provided.
|
|
287
294
|
*
|
|
288
295
|
* @param {string} name The name of the topic.
|
|
296
|
+
* @param {PublishOptions} [options] Publisher configuration object.
|
|
289
297
|
* @returns {Topic} A {@link Topic} instance.
|
|
290
298
|
*
|
|
291
299
|
* @example
|