@google-cloud/pubsub
Advanced tools
Comparing version 2.10.0 to 2.11.0
@@ -15,17 +15,10 @@ /*! | ||
*/ | ||
import { Attributes, SpanContext, Span } from '@opentelemetry/api'; | ||
import { SpanAttributes, SpanContext, Span, SpanKind } from '@opentelemetry/api'; | ||
/** | ||
* Wrapper for creating OpenTelemetry Spans | ||
* Creates a new span with the given properties | ||
* | ||
* @class | ||
* @param {string} spanName the name for the span | ||
* @param {Attributes?} attributes an object containing the attributes to be set for the span | ||
* @param {SpanContext?} parent the context of the parent span to link to the span | ||
*/ | ||
export declare class OpenTelemetryTracer { | ||
/** | ||
* Creates a new span with the given properties | ||
* | ||
* @param {string} spanName the name for the span | ||
* @param {Attributes?} attributes an object containing the attributes to be set for the span | ||
* @param {SpanContext?} parent the context of the parent span to link to the span | ||
*/ | ||
createSpan(spanName: string, attributes?: Attributes, parent?: SpanContext): Span; | ||
} | ||
export declare function createSpan(spanName: string, kind: SpanKind, attributes?: SpanAttributes, parent?: SpanContext): Span; |
@@ -17,26 +17,27 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OpenTelemetryTracer = void 0; | ||
exports.createSpan = void 0; | ||
const api_1 = require("@opentelemetry/api"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const PKG = require('../../package.json'); | ||
/** | ||
* Wrapper for creating OpenTelemetry Spans | ||
* @internal | ||
* Instantiates a Opentelemetry tracer for the library | ||
*/ | ||
const libraryTracer = api_1.trace.getTracer('@google-cloud/pubsub', PKG.version); | ||
/** | ||
* Creates a new span with the given properties | ||
* | ||
* @class | ||
* @param {string} spanName the name for the span | ||
* @param {Attributes?} attributes an object containing the attributes to be set for the span | ||
* @param {SpanContext?} parent the context of the parent span to link to the span | ||
*/ | ||
class OpenTelemetryTracer { | ||
/** | ||
* Creates a new span with the given properties | ||
* | ||
* @param {string} spanName the name for the span | ||
* @param {Attributes?} attributes an object containing the attributes to be set for the span | ||
* @param {SpanContext?} parent the context of the parent span to link to the span | ||
*/ | ||
createSpan(spanName, attributes, parent) { | ||
const tracerProvider = api_1.trace.getTracer('default'); | ||
return tracerProvider.startSpan(spanName, { | ||
parent: parent, | ||
attributes: attributes, | ||
}); | ||
} | ||
function createSpan(spanName, kind, attributes, parent) { | ||
return libraryTracer.startSpan(spanName, { | ||
// set the kind of the span | ||
kind, | ||
// set the attributes of the span | ||
attributes: attributes, | ||
}, parent ? api_1.setSpanContext(api_1.context.active(), parent) : undefined); | ||
} | ||
exports.OpenTelemetryTracer = OpenTelemetryTracer; | ||
exports.createSpan = createSpan; | ||
//# sourceMappingURL=opentelemetry-tracing.js.map |
@@ -24,3 +24,2 @@ /*! | ||
import { google } from '../../protos/protos'; | ||
import { OpenTelemetryTracer } from '../opentelemetry-tracing'; | ||
export declare type PubsubMessage = google.pubsub.v1.IPubsubMessage; | ||
@@ -65,3 +64,2 @@ export interface Attributes { | ||
orderedQueues: Map<string, OrderedQueue>; | ||
tracing: OpenTelemetryTracer | undefined; | ||
constructor(topic: Topic, options?: PublishOptions); | ||
@@ -68,0 +66,0 @@ flush(): Promise<void>; |
@@ -21,2 +21,4 @@ "use strict"; | ||
const extend = require("extend"); | ||
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions"); | ||
const api_1 = require("@opentelemetry/api"); | ||
const message_queues_1 = require("./message-queues"); | ||
@@ -57,6 +59,2 @@ const default_options_1 = require("../default-options"); | ||
this.orderedQueues = new Map(); | ||
this.tracing = | ||
this.settings && this.settings.enableOpenTelemetryTracing | ||
? new opentelemetry_tracing_1.OpenTelemetryTracer() | ||
: undefined; | ||
} | ||
@@ -181,5 +179,2 @@ /** | ||
const { batching, gaxOpts, messageOrdering, enableOpenTelemetryTracing, } = extend(true, defaults, options); | ||
this.tracing = enableOpenTelemetryTracing | ||
? new opentelemetry_tracing_1.OpenTelemetryTracer() | ||
: undefined; | ||
this.settings = { | ||
@@ -204,9 +199,22 @@ batching: { | ||
constructSpan(message) { | ||
var _a; | ||
if (!this.settings.enableOpenTelemetryTracing) { | ||
return undefined; | ||
} | ||
const spanAttributes = { | ||
data: message.data, | ||
// Add Opentelemetry semantic convention attributes to the span, based on: | ||
// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.1.0/specification/trace/semantic_conventions/messaging.md | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_TEMP_DESTINATION]: false, | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_SYSTEM]: 'pubsub', | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_OPERATION]: 'send', | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_DESTINATION]: this.topic.name, | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_DESTINATION_KIND]: 'topic', | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_MESSAGE_ID]: message.messageId, | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_PROTOCOL]: 'pubsub', | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES]: (_a = message.data) === null || _a === void 0 ? void 0 : _a.length, | ||
'messaging.pubsub.ordering_key': message.orderingKey, | ||
}; | ||
const span = this.tracing | ||
? this.tracing.createSpan(`${this.topic.name} publisher`, spanAttributes) | ||
: undefined; | ||
if (span) { | ||
const span = opentelemetry_tracing_1.createSpan(`${this.topic.name} send`, api_1.SpanKind.PRODUCER, spanAttributes); | ||
// If the span's context is valid we should pass the span context special attribute | ||
if (api_1.isSpanContextValid(span.context())) { | ||
if (message.attributes && | ||
@@ -213,0 +221,0 @@ message.attributes['googclient_OpenTelemetrySpanContext']) { |
@@ -48,2 +48,8 @@ "use strict"; | ||
}; | ||
if (messages.length === 0) { | ||
if (typeof callback === 'function') { | ||
callback(null); | ||
} | ||
return; | ||
} | ||
topic.request({ | ||
@@ -50,0 +56,0 @@ client: 'PublisherClient', |
@@ -143,2 +143,3 @@ /*! | ||
private _isUserSetDeadline; | ||
private _useOpentelemetry; | ||
private _latencies; | ||
@@ -150,3 +151,2 @@ private _modAcks; | ||
private _subscription; | ||
private _tracing; | ||
constructor(subscription: Subscription, options?: {}); | ||
@@ -153,0 +153,0 @@ /** |
@@ -23,2 +23,4 @@ "use strict"; | ||
const events_1 = require("events"); | ||
const api_1 = require("@opentelemetry/api"); | ||
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions"); | ||
const histogram_1 = require("./histogram"); | ||
@@ -212,2 +214,3 @@ const lease_manager_1 = require("./lease-manager"); | ||
this._isUserSetDeadline = false; | ||
this._useOpentelemetry = false; | ||
this._histogram = new histogram_1.Histogram({ min: 10, max: 600 }); | ||
@@ -346,2 +349,3 @@ this._latencies = new histogram_1.Histogram(); | ||
this._options = options; | ||
this._useOpentelemetry = options.enableOpenTelemetryTracing || false; | ||
if (options.ackDeadline) { | ||
@@ -369,5 +373,2 @@ this.ackDeadline = options.ackDeadline; | ||
} | ||
this._tracing = options.enableOpenTelemetryTracing | ||
? new opentelemetry_tracing_1.OpenTelemetryTracer() | ||
: undefined; | ||
} | ||
@@ -382,3 +383,3 @@ /** | ||
// Handle cases where OpenTelemetry is disabled or no span context was sent through message | ||
if (!this._tracing || | ||
if (!this._useOpentelemetry || | ||
!message.attributes || | ||
@@ -393,9 +394,25 @@ !message.attributes['googclient_OpenTelemetrySpanContext']) { | ||
const spanAttributes = { | ||
// Original span attributes | ||
ackId: message.ackId, | ||
deliveryAttempt: message.deliveryAttempt, | ||
// | ||
// based on https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/messaging.md#topic-with-multiple-consumers | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_SYSTEM]: 'pubsub', | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_OPERATION]: 'process', | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_DESTINATION]: this.name, | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_DESTINATION_KIND]: 'topic', | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_MESSAGE_ID]: message.id, | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_PROTOCOL]: 'pubsub', | ||
[semantic_conventions_1.MessagingAttribute.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES]: message.data | ||
.length, | ||
// Not in Opentelemetry semantic convention but mimics naming | ||
'messaging.pubsub.received_at': message.received, | ||
'messaging.pubsub.acknowlege_id': message.ackId, | ||
'messaging.pubsub.delivery_attempt': message.deliveryAttempt, | ||
}; | ||
// Subscriber spans should always have a publisher span as a parent. | ||
// Return undefined if no parent is provided | ||
const spanName = `${this.name} process`; | ||
const span = parentSpanContext | ||
? this._tracing.createSpan(this._name, spanAttributes, parentSpanContext) | ||
? opentelemetry_tracing_1.createSpan(spanName.trim(), api_1.SpanKind.CONSUMER, spanAttributes, parentSpanContext) | ||
: undefined; | ||
@@ -402,0 +419,0 @@ return span; |
@@ -90,4 +90,13 @@ /*! | ||
* for messages automatically as long as there is at least one listener assigned | ||
* for the `message` event. | ||
* for the `message` event. Available events: | ||
* | ||
* Upon receipt of a message: | ||
* on(event: 'message', listener: (message: {@link Message}) => void): this; | ||
* | ||
* Upon receipt of an error: | ||
* on(event: 'error', listener: (error: Error) => void): this; | ||
* | ||
* Upon the closing of the subscriber: | ||
* on(event: 'close', listener: Function): this; | ||
* | ||
* By default Subscription objects allow you to process 100 messages at the same | ||
@@ -94,0 +103,0 @@ * time. You can fine tune this value by adjusting the |
@@ -26,2 +26,27 @@ "use strict"; | ||
const subscriber_1 = require("./subscriber"); | ||
// JSDoc won't see these, so this is just to let you get typings | ||
// in your editor of choice. | ||
// | ||
// NOTE: These are commented out for now because we don't want to | ||
// break any existing clients that rely on not-entirely-correct | ||
// typings. We'll re-enable on the next major. | ||
/* export declare interface Subscription { | ||
on( | ||
event: 'message', | ||
listener: (message: Message) => void | ||
): this; | ||
on( | ||
event: 'error', | ||
listener: (error: StatusError) => void | ||
): this; | ||
on(event: 'close', listener: () => void): this; | ||
// Only used internally. | ||
on(event: 'newListener', listener: Function): this; | ||
on(event: 'removeListener', listener: Function): this; | ||
// Catch-all. If you get an error about this line, it means you're | ||
// using an unsupported event type or listener type. | ||
on(event: string, listener: void): this; | ||
} */ | ||
/** | ||
@@ -59,4 +84,13 @@ * @typedef {object} ExpirationPolicy | ||
* for messages automatically as long as there is at least one listener assigned | ||
* for the `message` event. | ||
* for the `message` event. Available events: | ||
* | ||
* Upon receipt of a message: | ||
* on(event: 'message', listener: (message: {@link Message}) => void): this; | ||
* | ||
* Upon receipt of an error: | ||
* on(event: 'error', listener: (error: Error) => void): this; | ||
* | ||
* Upon the closing of the subscriber: | ||
* on(event: 'close', listener: Function): this; | ||
* | ||
* By default Subscription objects allow you to process 100 messages at the same | ||
@@ -63,0 +97,0 @@ * time. You can fine tune this value by adjusting the |
@@ -292,4 +292,2 @@ "use strict"; | ||
* Settings for validating messages published against a schema. | ||
* | ||
* EXPERIMENTAL: Schema support is in development and may not work yet. | ||
* @param {boolean} request.satisfiesPzs | ||
@@ -296,0 +294,0 @@ * Reserved for future use. This field is set only in responses from the |
@@ -7,2 +7,3 @@ /// <reference types="node" /> | ||
/** | ||
* Service for doing schema-related operations. | ||
* @class | ||
@@ -9,0 +10,0 @@ * @memberof v1 |
@@ -33,2 +33,3 @@ "use strict"; | ||
/** | ||
* Service for doing schema-related operations. | ||
* @class | ||
@@ -35,0 +36,0 @@ * @memberof v1 |
@@ -7,2 +7,18 @@ # Changelog | ||
## [2.11.0](https://www.github.com/googleapis/nodejs-pubsub/compare/v2.10.0...v2.11.0) (2021-04-14) | ||
### ⚠ BREAKING CHANGES | ||
* `fix: added support for Opentelemetry 0.18` - makes significant changes to OpenTelemetry support in order to unblock its usage again; the main user-visible change is that you will need to use 0.18+ versions of OpenTelemetry, and different items are passed to the server in spans. | ||
### Bug Fixes | ||
* added support for Opentelemetry 0.18 ([#1234](https://www.github.com/googleapis/nodejs-pubsub/issues/1234)) ([aedc36c](https://www.github.com/googleapis/nodejs-pubsub/commit/aedc36c3f8736eff1cb781b9e05457463481b3d6)) | ||
* follow-on proto updates from the removal of the common protos ([#1229](https://www.github.com/googleapis/nodejs-pubsub/issues/1229)) ([cb627d5](https://www.github.com/googleapis/nodejs-pubsub/commit/cb627d5555c617eb025181c9f9aaf1d2c9621a86)) | ||
* prevent attempt to publish 0 messages ([#1218](https://www.github.com/googleapis/nodejs-pubsub/issues/1218)) ([96e6535](https://www.github.com/googleapis/nodejs-pubsub/commit/96e653514b35d61f74ba2d5d6fa96e19bc45bf8c)) | ||
* remove common protos ([#1232](https://www.github.com/googleapis/nodejs-pubsub/issues/1232)) ([8838288](https://www.github.com/googleapis/nodejs-pubsub/commit/883828800c94f7ea21c8306d272b70b4576c664c)) | ||
* reverting the major from the OpenTelemetry change (it was already broken) ([#1257](https://www.github.com/googleapis/nodejs-pubsub/issues/1257)) ([09c428a](https://www.github.com/googleapis/nodejs-pubsub/commit/09c428a17eb20fcd0fc45301addb48d2bebc56a3)) | ||
* temporarily pin sinon at 10.0.0 ([#1252](https://www.github.com/googleapis/nodejs-pubsub/issues/1252)) ([0922164](https://www.github.com/googleapis/nodejs-pubsub/commit/09221643be0693463ed4e5d56efd0f1ebfbe78b7)) | ||
## [2.10.0](https://www.github.com/googleapis/nodejs-pubsub/compare/v2.9.0...v2.10.0) (2021-02-22) | ||
@@ -9,0 +25,0 @@ |
{ | ||
"name": "@google-cloud/pubsub", | ||
"description": "Cloud Pub/Sub Client Library for Node.js", | ||
"version": "2.10.0", | ||
"version": "2.11.0", | ||
"license": "Apache-2.0", | ||
@@ -56,4 +56,4 @@ "author": "Google Inc.", | ||
"@google-cloud/promisify": "^2.0.0", | ||
"@opentelemetry/api": "^0.12.0", | ||
"@opentelemetry/tracing": "^0.12.0", | ||
"@opentelemetry/api": "^0.18.1", | ||
"@opentelemetry/semantic-conventions": "^0.18.2", | ||
"@types/duplexify": "^3.6.0", | ||
@@ -70,3 +70,6 @@ "@types/long": "^4.0.0", | ||
"devDependencies": { | ||
"@grpc/proto-loader": "^0.5.4", | ||
"@grpc/proto-loader": "^0.6.0", | ||
"@microsoft/api-documenter": "^7.8.10", | ||
"@microsoft/api-extractor": "^7.8.10", | ||
"@opentelemetry/tracing": "^0.18.0", | ||
"@types/execa": "^0.9.0", | ||
@@ -80,3 +83,3 @@ "@types/extend": "^3.0.0", | ||
"@types/proxyquire": "^1.3.28", | ||
"@types/sinon": "^9.0.0", | ||
"@types/sinon": "^10.0.0", | ||
"@types/tmp": "^0.2.0", | ||
@@ -98,3 +101,3 @@ "@types/uuid": "^8.0.0", | ||
"proxyquire": "^2.0.0", | ||
"sinon": "^9.0.0", | ||
"sinon": "^10.0.0", | ||
"tmp": "^0.2.0", | ||
@@ -106,6 +109,4 @@ "ts-loader": "^8.0.0", | ||
"webpack-cli": "^4.0.0", | ||
"yargs": "^16.0.0", | ||
"@microsoft/api-documenter": "^7.8.10", | ||
"@microsoft/api-extractor": "^7.8.10" | ||
"yargs": "^16.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47933
171
1
1
1
17
2856334
37
82
+ Added@opentelemetry/api@0.18.1(transitive)
+ Added@opentelemetry/semantic-conventions@0.18.2(transitive)
- Removed@opentelemetry/tracing@^0.12.0
- Removed@opentelemetry/api@0.12.0(transitive)
- Removed@opentelemetry/context-base@0.12.0(transitive)
- Removed@opentelemetry/core@0.12.0(transitive)
- Removed@opentelemetry/resources@0.12.0(transitive)
- Removed@opentelemetry/semantic-conventions@0.12.0(transitive)
- Removed@opentelemetry/tracing@0.12.0(transitive)
- Removedsemver@7.6.3(transitive)
Updated@opentelemetry/api@^0.18.1