@azure/event-hubs 5.7.0-beta.1 → 5.7.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +1 -9
  2. package/README.md +1 -1
  3. package/dist/index.js +38 -729
  4. package/dist/index.js.map +1 -1
  5. package/dist-esm/src/diagnostics/instrumentEventData.js +15 -33
  6. package/dist-esm/src/diagnostics/instrumentEventData.js.map +1 -1
  7. package/dist-esm/src/diagnostics/tracing.js.map +1 -1
  8. package/dist-esm/src/eventDataBatch.js +17 -6
  9. package/dist-esm/src/eventDataBatch.js.map +1 -1
  10. package/dist-esm/src/eventHubProducerClient.js +11 -2
  11. package/dist-esm/src/eventHubProducerClient.js.map +1 -1
  12. package/dist-esm/src/index.js +0 -1
  13. package/dist-esm/src/index.js.map +1 -1
  14. package/dist-esm/src/util/constants.js +1 -1
  15. package/dist-esm/src/util/constants.js.map +1 -1
  16. package/package.json +15 -19
  17. package/types/3.1/event-hubs.d.ts +2 -287
  18. package/types/latest/event-hubs.d.ts +2 -310
  19. package/types/latest/tsdoc-metadata.json +1 -1
  20. package/dist-esm/src/batchingPartitionChannel.js +0 -241
  21. package/dist-esm/src/batchingPartitionChannel.js.map +0 -1
  22. package/dist-esm/src/eventHubBufferedProducerClient.js +0 -242
  23. package/dist-esm/src/eventHubBufferedProducerClient.js.map +0 -1
  24. package/dist-esm/src/impl/awaitableQueue.js +0 -46
  25. package/dist-esm/src/impl/awaitableQueue.js.map +0 -1
  26. package/dist-esm/src/impl/partitionAssigner.js +0 -54
  27. package/dist-esm/src/impl/partitionAssigner.js.map +0 -1
  28. package/dist-esm/src/impl/patitionKeyToIdMapper.js +0 -106
  29. package/dist-esm/src/impl/patitionKeyToIdMapper.js.map +0 -1
  30. package/dist-esm/src/util/getPromiseParts.js +0 -20
  31. package/dist-esm/src/util/getPromiseParts.js.map +0 -1
@@ -1,8 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { extractSpanContextFromTraceParentHeader, getTraceParentHeader, isSpanContextValid } from "@azure/core-tracing";
3
+ import { extractSpanContextFromTraceParentHeader, getTraceParentHeader } from "@azure/core-tracing";
4
4
  import { isAmqpAnnotatedMessage } from "../eventData";
5
- import { createMessageSpan } from "./tracing";
6
5
  /**
7
6
  * @hidden
8
7
  */
@@ -14,43 +13,26 @@ export const TRACEPARENT_PROPERTY = "Diagnostic-Id";
14
13
  * @param eventData - The `EventData` or `AmqpAnnotatedMessage` to instrument.
15
14
  * @param span - The `Span` containing the context to propagate tracing information.
16
15
  */
17
- export function instrumentEventData(eventData, options, entityPath, host) {
16
+ export function instrumentEventData(eventData, span) {
18
17
  const props = isAmqpAnnotatedMessage(eventData)
19
18
  ? eventData.applicationProperties
20
19
  : eventData.properties;
21
- // check if the event has already been instrumented
22
- const previouslyInstrumented = Boolean(props === null || props === void 0 ? void 0 : props[TRACEPARENT_PROPERTY]);
23
- if (previouslyInstrumented) {
24
- return { event: eventData, spanContext: undefined };
20
+ if (props && props[TRACEPARENT_PROPERTY]) {
21
+ return eventData;
25
22
  }
26
- const { span: messageSpan } = createMessageSpan(options, { entityPath, host });
27
- try {
28
- if (!messageSpan.isRecording()) {
29
- return {
30
- event: eventData,
31
- spanContext: undefined
32
- };
33
- }
34
- const traceParent = getTraceParentHeader(messageSpan.spanContext());
35
- if (traceParent && isSpanContextValid(messageSpan.spanContext())) {
36
- const copiedProps = Object.assign({}, props);
37
- // create a copy so the original isn't modified
38
- if (isAmqpAnnotatedMessage(eventData)) {
39
- eventData = Object.assign(Object.assign({}, eventData), { applicationProperties: copiedProps });
40
- }
41
- else {
42
- eventData = Object.assign(Object.assign({}, eventData), { properties: copiedProps });
43
- }
44
- copiedProps[TRACEPARENT_PROPERTY] = traceParent;
45
- }
46
- return {
47
- event: eventData,
48
- spanContext: messageSpan.spanContext()
49
- };
23
+ const copiedProps = Object.assign({}, props);
24
+ // create a copy so the original isn't modified
25
+ if (isAmqpAnnotatedMessage(eventData)) {
26
+ eventData = Object.assign(Object.assign({}, eventData), { applicationProperties: copiedProps });
50
27
  }
51
- finally {
52
- messageSpan.end();
28
+ else {
29
+ eventData = Object.assign(Object.assign({}, eventData), { properties: copiedProps });
53
30
  }
31
+ const traceParent = getTraceParentHeader(span.spanContext());
32
+ if (traceParent) {
33
+ copiedProps[TRACEPARENT_PROPERTY] = traceParent;
34
+ }
35
+ return eventData;
54
36
  }
55
37
  /**
56
38
  * Extracts the `SpanContext` from an `EventData` if the context exists.
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentEventData.js","sourceRoot":"","sources":["../../../src/diagnostics/instrumentEventData.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,uCAAuC,EACvC,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAa,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAA2C,EAC3C,OAAyB,EACzB,UAAkB,EAClB,IAAY;IAEZ,MAAM,KAAK,GAAG,sBAAsB,CAAC,SAAS,CAAC;QAC7C,CAAC,CAAC,SAAS,CAAC,qBAAqB;QACjC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC;IAEzB,mDAAmD;IACnD,MAAM,sBAAsB,GAAG,OAAO,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,oBAAoB,CAAC,CAAC,CAAC;IAEtE,IAAI,sBAAsB,EAAE;QAC1B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;KACrD;IAED,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,iBAAiB,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/E,IAAI;QACF,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE;YAC9B,OAAO;gBACL,KAAK,EAAE,SAAS;gBAChB,WAAW,EAAE,SAAS;aACvB,CAAC;SACH;QAED,MAAM,WAAW,GAAG,oBAAoB,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC;QACpE,IAAI,WAAW,IAAI,kBAAkB,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,EAAE;YAChE,MAAM,WAAW,qBAAQ,KAAK,CAAE,CAAC;YAEjC,+CAA+C;YAC/C,IAAI,sBAAsB,CAAC,SAAS,CAAC,EAAE;gBACrC,SAAS,mCAAQ,SAAS,KAAE,qBAAqB,EAAE,WAAW,GAAE,CAAC;aAClE;iBAAM;gBACL,SAAS,mCAAQ,SAAS,KAAE,UAAU,EAAE,WAAW,GAAE,CAAC;aACvD;YACD,WAAW,CAAC,oBAAoB,CAAC,GAAG,WAAW,CAAC;SACjD;QAED,OAAO;YACL,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,WAAW,CAAC,WAAW,EAAE;SACvC,CAAC;KACH;YAAS;QACR,WAAW,CAAC,GAAG,EAAE,CAAC;KACnB;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,SAAoB;IAClE,IAAI,CAAC,SAAS,CAAC,UAAU,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE;QACxE,OAAO;KACR;IAED,MAAM,YAAY,GAAG,SAAS,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAChE,OAAO,uCAAuC,CAAC,YAAY,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n extractSpanContextFromTraceParentHeader,\n getTraceParentHeader,\n isSpanContextValid\n} from \"@azure/core-tracing\";\nimport { SpanContext } from \"@azure/core-tracing\";\nimport { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { EventData, isAmqpAnnotatedMessage } from \"../eventData\";\nimport { OperationOptions } from \"../util/operationOptions\";\nimport { createMessageSpan } from \"./tracing\";\n\n/**\n * @hidden\n */\nexport const TRACEPARENT_PROPERTY = \"Diagnostic-Id\";\n\n/**\n * Populates the `EventData` with `SpanContext` info to support trace propagation.\n * Creates and returns a copy of the passed in `EventData` unless the `EventData`\n * has already been instrumented.\n * @param eventData - The `EventData` or `AmqpAnnotatedMessage` to instrument.\n * @param span - The `Span` containing the context to propagate tracing information.\n */\nexport function instrumentEventData(\n eventData: EventData | AmqpAnnotatedMessage,\n options: OperationOptions,\n entityPath: string,\n host: string\n): { event: EventData; spanContext: SpanContext | undefined } {\n const props = isAmqpAnnotatedMessage(eventData)\n ? eventData.applicationProperties\n : eventData.properties;\n\n // check if the event has already been instrumented\n const previouslyInstrumented = Boolean(props?.[TRACEPARENT_PROPERTY]);\n\n if (previouslyInstrumented) {\n return { event: eventData, spanContext: undefined };\n }\n\n const { span: messageSpan } = createMessageSpan(options, { entityPath, host });\n try {\n if (!messageSpan.isRecording()) {\n return {\n event: eventData,\n spanContext: undefined\n };\n }\n\n const traceParent = getTraceParentHeader(messageSpan.spanContext());\n if (traceParent && isSpanContextValid(messageSpan.spanContext())) {\n const copiedProps = { ...props };\n\n // create a copy so the original isn't modified\n if (isAmqpAnnotatedMessage(eventData)) {\n eventData = { ...eventData, applicationProperties: copiedProps };\n } else {\n eventData = { ...eventData, properties: copiedProps };\n }\n copiedProps[TRACEPARENT_PROPERTY] = traceParent;\n }\n\n return {\n event: eventData,\n spanContext: messageSpan.spanContext()\n };\n } finally {\n messageSpan.end();\n }\n}\n\n/**\n * Extracts the `SpanContext` from an `EventData` if the context exists.\n * @param eventData - An individual `EventData` object.\n * @internal\n */\nexport function extractSpanContextFromEventData(eventData: EventData): SpanContext | undefined {\n if (!eventData.properties || !eventData.properties[TRACEPARENT_PROPERTY]) {\n return;\n }\n\n const diagnosticId = eventData.properties[TRACEPARENT_PROPERTY];\n return extractSpanContextFromTraceParentHeader(diagnosticId);\n}\n"]}
1
+ {"version":3,"file":"instrumentEventData.js","sourceRoot":"","sources":["../../../src/diagnostics/instrumentEventData.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,uCAAuC,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGpG,OAAO,EAAa,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEjE;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAA2C,EAC3C,IAAU;IAEV,MAAM,KAAK,GAAG,sBAAsB,CAAC,SAAS,CAAC;QAC7C,CAAC,CAAC,SAAS,CAAC,qBAAqB;QACjC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC;IAEzB,IAAI,KAAK,IAAI,KAAK,CAAC,oBAAoB,CAAC,EAAE;QACxC,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,WAAW,qBAAQ,KAAK,CAAE,CAAC;IAEjC,+CAA+C;IAC/C,IAAI,sBAAsB,CAAC,SAAS,CAAC,EAAE;QACrC,SAAS,mCAAQ,SAAS,KAAE,qBAAqB,EAAE,WAAW,GAAE,CAAC;KAClE;SAAM;QACL,SAAS,mCAAQ,SAAS,KAAE,UAAU,EAAE,WAAW,GAAE,CAAC;KACvD;IAED,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC7D,IAAI,WAAW,EAAE;QACf,WAAW,CAAC,oBAAoB,CAAC,GAAG,WAAW,CAAC;KACjD;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,SAAoB;IAClE,IAAI,CAAC,SAAS,CAAC,UAAU,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE;QACxE,OAAO;KACR;IAED,MAAM,YAAY,GAAG,SAAS,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAChE,OAAO,uCAAuC,CAAC,YAAY,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { extractSpanContextFromTraceParentHeader, getTraceParentHeader } from \"@azure/core-tracing\";\nimport { Span, SpanContext } from \"@azure/core-tracing\";\nimport { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { EventData, isAmqpAnnotatedMessage } from \"../eventData\";\n\n/**\n * @hidden\n */\nexport const TRACEPARENT_PROPERTY = \"Diagnostic-Id\";\n\n/**\n * Populates the `EventData` with `SpanContext` info to support trace propagation.\n * Creates and returns a copy of the passed in `EventData` unless the `EventData`\n * has already been instrumented.\n * @param eventData - The `EventData` or `AmqpAnnotatedMessage` to instrument.\n * @param span - The `Span` containing the context to propagate tracing information.\n */\nexport function instrumentEventData(\n eventData: EventData | AmqpAnnotatedMessage,\n span: Span\n): EventData {\n const props = isAmqpAnnotatedMessage(eventData)\n ? eventData.applicationProperties\n : eventData.properties;\n\n if (props && props[TRACEPARENT_PROPERTY]) {\n return eventData;\n }\n\n const copiedProps = { ...props };\n\n // create a copy so the original isn't modified\n if (isAmqpAnnotatedMessage(eventData)) {\n eventData = { ...eventData, applicationProperties: copiedProps };\n } else {\n eventData = { ...eventData, properties: copiedProps };\n }\n\n const traceParent = getTraceParentHeader(span.spanContext());\n if (traceParent) {\n copiedProps[TRACEPARENT_PROPERTY] = traceParent;\n }\n\n return eventData;\n}\n\n/**\n * Extracts the `SpanContext` from an `EventData` if the context exists.\n * @param eventData - An individual `EventData` object.\n * @internal\n */\nexport function extractSpanContextFromEventData(eventData: EventData): SpanContext | undefined {\n if (!eventData.properties || !eventData.properties[TRACEPARENT_PROPERTY]) {\n return;\n }\n\n const diagnosticId = eventData.properties[TRACEPARENT_PROPERTY];\n return extractSpanContextFromTraceParentHeader(diagnosticId);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../../src/diagnostics/tracing.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,kBAAkB,EAGlB,OAAO,EACP,cAAc,EAEd,QAAQ,EACR,OAAO,EACR,MAAM,qBAAqB,CAAC;AAK7B,MAAM,WAAW,GAAG,kBAAkB,CAAC;IACrC,SAAS,EAAE,oBAAoB;IAC/B,aAAa,EAAE,iBAAiB;CACjC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,aAAqB,EACrB,gBAA8C,EAC9C,gBAAuE,EACvE,qBAAmC;;IAEnC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,WAAW,CAAC,aAAa,kCACrD,gBAAgB,KACnB,cAAc,kCACT,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,cAAc,KACnC,WAAW,kCAEN,MAAC,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,cAAsB,0CAAE,WAAW,GACtD,qBAAqB,QAG5B,CAAC;IAEH,IAAI,CAAC,YAAY,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC1E,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAEzD,OAAO;QACL,IAAI;QACJ,cAAc;KACf,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,gBAAkC,EAClC,cAAqE;IAErE,OAAO,kBAAkB,CAAC,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE;QACrE,IAAI,EAAE,QAAQ,CAAC,QAAQ;KACxB,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oCAAoC,CAAC,aAA4B;IAC/E,gEAAgE;IAChE,2GAA2G;IAC3G,MAAM,6BAA6B,GAAG,aAAa,CAAC,UAAU,CAAC;IAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA+BE;IAEF,IAAI,CAAC,6BAA6B,IAAI,aAAa,CAAC,cAAc,EAAE;QAClE,6EAA6E;QAC7E,0CAA0C;QAC1C,OAAO,aAAa,CAAC;KACtB;IAED,MAAM,gBAAgB,mCACjB,aAAa,KAChB,cAAc,EAAE;YACd,cAAc,EAAE,MAAM,CAAC,6BAA6B,CAAC;gBACnD,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,6BAA6B,CAAC;gBAC1D,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,6BAA6B,CAAC;SACpE,GACF,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,SAAS,MAAM,CAAC,YAA4C;IAC1D,IAAI,YAAY,IAAI,IAAI,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IAED,MAAM,CAAC,GAAG,YAAoB,CAAC;IAC/B,OAAO,OAAO,CAAC,CAAC,WAAW,KAAK,UAAU,CAAC;AAC7C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n createSpanFunction,\n SpanContext,\n SpanOptions,\n setSpan,\n setSpanContext,\n Span,\n SpanKind,\n context\n} from \"@azure/core-tracing\";\nimport { TryAddOptions } from \"../eventDataBatch\";\nimport { EventHubConnectionConfig } from \"../eventhubConnectionConfig\";\nimport { OperationOptions } from \"../util/operationOptions\";\n\nconst _createSpan = createSpanFunction({\n namespace: \"Microsoft.EventHub\",\n packagePrefix: \"Azure.EventHubs\"\n});\n\n/**\n * Creates an EventHubs specific span, with peer.address and message_bus.destination filled out.\n * @internal\n */\nexport function createEventHubSpan(\n operationName: string,\n operationOptions: OperationOptions | undefined,\n connectionConfig: Pick<EventHubConnectionConfig, \"entityPath\" | \"host\">,\n additionalSpanOptions?: SpanOptions\n): { span: Span; updatedOptions: OperationOptions } {\n const { span, updatedOptions } = _createSpan(operationName, {\n ...operationOptions,\n tracingOptions: {\n ...operationOptions?.tracingOptions,\n spanOptions: {\n // By passing spanOptions if they exist at runtime, we're backwards compatible with @azure/core-tracing@preview.13 and earlier.\n ...(operationOptions?.tracingOptions as any)?.spanOptions,\n ...additionalSpanOptions\n }\n }\n });\n\n span.setAttribute(\"message_bus.destination\", connectionConfig.entityPath);\n span.setAttribute(\"peer.address\", connectionConfig.host);\n\n return {\n span,\n updatedOptions\n };\n}\n\n/**\n * @internal\n */\nexport function createMessageSpan(\n operationOptions: OperationOptions,\n eventHubConfig: Pick<EventHubConnectionConfig, \"entityPath\" | \"host\">\n): ReturnType<typeof createEventHubSpan> {\n return createEventHubSpan(\"message\", operationOptions, eventHubConfig, {\n kind: SpanKind.PRODUCER\n });\n}\n\n/**\n * Converts TryAddOptions into the modern shape (OperationOptions) when needed.\n * (this is something we can eliminate at the next major release of EH _or_ when\n * we release with the GA version of opentelemetry).\n *\n * @internal\n */\nexport function convertTryAddOptionsForCompatibility(tryAddOptions: TryAddOptions): TryAddOptions {\n /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */\n // @ts-ignore: parentSpan is deprecated and this is compat code to translate it until we can get rid of it.\n const legacyParentSpanOrSpanContext = tryAddOptions.parentSpan;\n\n /*\n Our goal here is to offer compatibility but there is a case where a user might accidentally pass\n _both_ sets of options. We'll assume they want the OperationTracingOptions code path in that case.\n\n Example of accidental span passing:\n\n const someOptionsPassedIntoTheirFunction = {\n parentSpan: span; // set somewhere else in their code\n }\n\n function takeSomeOptionsFromSomewhere(someOptionsPassedIntoTheirFunction) {\n \n batch.tryAddMessage(message, { \n // \"runtime\" blend of options from some other part of their app\n ...someOptionsPassedIntoTheirFunction, // parentSpan comes along for the ride...\n\n tracingOptions: {\n // thank goodness, I'm doing this right! (thinks the developer)\n spanOptions: {\n context: context\n }\n }\n });\n }\n\n And now they've accidentally been opted into the legacy code path even though they think\n they're using the modern code path.\n \n This does kick the can down the road a bit - at some point we will be putting them in this\n situation where things looked okay but their spans are becoming unparented but we can \n try to announce this (and other changes related to tracing) in our next big rev.\n */\n\n if (!legacyParentSpanOrSpanContext || tryAddOptions.tracingOptions) {\n // assume that the options are already in the modern shape even if (possibly)\n // they were still specifying `parentSpan`\n return tryAddOptions;\n }\n\n const convertedOptions: TryAddOptions = {\n ...tryAddOptions,\n tracingOptions: {\n tracingContext: isSpan(legacyParentSpanOrSpanContext)\n ? setSpan(context.active(), legacyParentSpanOrSpanContext)\n : setSpanContext(context.active(), legacyParentSpanOrSpanContext)\n }\n };\n\n return convertedOptions;\n}\n\nfunction isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span {\n if (possibleSpan == null) {\n return false;\n }\n\n const x = possibleSpan as Span;\n return typeof x.spanContext === \"function\";\n}\n"]}
1
+ {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../../src/diagnostics/tracing.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,kBAAkB,EAGlB,OAAO,EACP,cAAc,EAEd,QAAQ,EACR,OAAO,EACR,MAAM,qBAAqB,CAAC;AAK7B,MAAM,WAAW,GAAG,kBAAkB,CAAC;IACrC,SAAS,EAAE,oBAAoB;IAC/B,aAAa,EAAE,iBAAiB;CACjC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,aAAqB,EACrB,gBAA8C,EAC9C,gBAAuE,EACvE,qBAAmC;;IAEnC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,WAAW,CAAC,aAAa,kCACrD,gBAAgB,KACnB,cAAc,kCACT,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,cAAc,KACnC,WAAW,kCACN,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,cAAc,0CAAE,WAAW,GAC7C,qBAAqB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C","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n createSpanFunction,\n SpanContext,\n SpanOptions,\n setSpan,\n setSpanContext,\n Span,\n SpanKind,\n context\n} from \"@azure/core-tracing\";\nimport { TryAddOptions } from \"../eventDataBatch\";\nimport { EventHubConnectionConfig } from \"../eventhubConnectionConfig\";\nimport { OperationOptions } from \"../util/operationOptions\";\n\nconst _createSpan = createSpanFunction({\n namespace: \"Microsoft.EventHub\",\n packagePrefix: \"Azure.EventHubs\"\n});\n\n/**\n * Creates an EventHubs specific span, with peer.address and message_bus.destination filled out.\n * @internal\n */\nexport function createEventHubSpan(\n operationName: string,\n operationOptions: OperationOptions | undefined,\n connectionConfig: Pick<EventHubConnectionConfig, \"entityPath\" | \"host\">,\n additionalSpanOptions?: SpanOptions\n): { span: Span; updatedOptions: OperationOptions } {\n const { span, updatedOptions } = _createSpan(operationName, {\n ...operationOptions,\n tracingOptions: {\n ...operationOptions?.tracingOptions,\n spanOptions: {\n ...operationOptions?.tracingOptions?.spanOptions,\n ...additionalSpanOptions\n }\n }\n });\n\n span.setAttribute(\"message_bus.destination\", connectionConfig.entityPath);\n span.setAttribute(\"peer.address\", connectionConfig.host);\n\n return {\n span,\n updatedOptions\n };\n}\n\n/**\n * @internal\n */\nexport function createMessageSpan(\n operationOptions: OperationOptions,\n eventHubConfig: Pick<EventHubConnectionConfig, \"entityPath\" | \"host\">\n): ReturnType<typeof createEventHubSpan> {\n return createEventHubSpan(\"message\", operationOptions, eventHubConfig, {\n kind: SpanKind.PRODUCER\n });\n}\n\n/**\n * Converts TryAddOptions into the modern shape (OperationOptions) when needed.\n * (this is something we can eliminate at the next major release of EH _or_ when\n * we release with the GA version of opentelemetry).\n *\n * @internal\n */\nexport function convertTryAddOptionsForCompatibility(tryAddOptions: TryAddOptions): TryAddOptions {\n /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */\n // @ts-ignore: parentSpan is deprecated and this is compat code to translate it until we can get rid of it.\n const legacyParentSpanOrSpanContext = tryAddOptions.parentSpan;\n\n /*\n Our goal here is to offer compatibility but there is a case where a user might accidentally pass\n _both_ sets of options. We'll assume they want the OperationTracingOptions code path in that case.\n\n Example of accidental span passing:\n\n const someOptionsPassedIntoTheirFunction = {\n parentSpan: span; // set somewhere else in their code\n }\n\n function takeSomeOptionsFromSomewhere(someOptionsPassedIntoTheirFunction) {\n \n batch.tryAddMessage(message, { \n // \"runtime\" blend of options from some other part of their app\n ...someOptionsPassedIntoTheirFunction, // parentSpan comes along for the ride...\n\n tracingOptions: {\n // thank goodness, I'm doing this right! (thinks the developer)\n spanOptions: {\n context: context\n }\n }\n });\n }\n\n And now they've accidentally been opted into the legacy code path even though they think\n they're using the modern code path.\n \n This does kick the can down the road a bit - at some point we will be putting them in this\n situation where things looked okay but their spans are becoming unparented but we can \n try to announce this (and other changes related to tracing) in our next big rev.\n */\n\n if (!legacyParentSpanOrSpanContext || tryAddOptions.tracingOptions) {\n // assume that the options are already in the modern shape even if (possibly)\n // they were still specifying `parentSpan`\n return tryAddOptions;\n }\n\n const convertedOptions: TryAddOptions = {\n ...tryAddOptions,\n tracingOptions: {\n tracingContext: isSpan(legacyParentSpanOrSpanContext)\n ? setSpan(context.active(), legacyParentSpanOrSpanContext)\n : setSpanContext(context.active(), legacyParentSpanOrSpanContext)\n }\n };\n\n return convertedOptions;\n}\n\nfunction isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span {\n if (possibleSpan == null) {\n return false;\n }\n\n const x = possibleSpan as Span;\n return typeof x.spanContext === \"function\";\n}\n"]}
@@ -1,10 +1,10 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { toRheaMessage } from "./eventData";
3
+ import { isAmqpAnnotatedMessage, toRheaMessage } from "./eventData";
4
4
  import { message } from "rhea-promise";
5
5
  import { throwTypeErrorIfParameterMissing } from "./util/error";
6
- import { instrumentEventData } from "./diagnostics/instrumentEventData";
7
- import { convertTryAddOptionsForCompatibility } from "./diagnostics/tracing";
6
+ import { TRACEPARENT_PROPERTY, instrumentEventData } from "./diagnostics/instrumentEventData";
7
+ import { convertTryAddOptionsForCompatibility, createMessageSpan } from "./diagnostics/tracing";
8
8
  import { isDefined, isObjectWithProperties } from "./util/typeGuards";
9
9
  /**
10
10
  * The amount of bytes to reserve as overhead for a small message.
@@ -137,12 +137,23 @@ export class EventDataBatchImpl {
137
137
  * @returns A boolean value indicating if the event data has been added to the batch or not.
138
138
  */
139
139
  tryAdd(eventData, options = {}) {
140
+ var _a;
140
141
  throwTypeErrorIfParameterMissing(this._context.connectionId, "tryAdd", "eventData", eventData);
141
142
  options = convertTryAddOptionsForCompatibility(options);
142
- const { entityPath, host } = this._context.config;
143
- const { event: instrumentedEvent, spanContext } = instrumentEventData(eventData, options, entityPath, host);
143
+ // check if the event has already been instrumented
144
+ const previouslyInstrumented = Boolean((_a = (isAmqpAnnotatedMessage(eventData)
145
+ ? eventData.applicationProperties
146
+ : eventData.properties)) === null || _a === void 0 ? void 0 : _a[TRACEPARENT_PROPERTY] // Event Data maps properties to applicationProperties.
147
+ );
148
+ let spanContext;
149
+ if (!previouslyInstrumented) {
150
+ const { span: messageSpan } = createMessageSpan(options, this._context.config);
151
+ eventData = instrumentEventData(eventData, messageSpan);
152
+ spanContext = messageSpan.spanContext();
153
+ messageSpan.end();
154
+ }
144
155
  // Convert EventData to RheaMessage.
145
- const amqpMessage = toRheaMessage(instrumentedEvent, this._partitionKey);
156
+ const amqpMessage = toRheaMessage(eventData, this._partitionKey);
146
157
  const encodedMessage = message.encode(amqpMessage);
147
158
  let currentSize = this._sizeInBytes;
148
159
  // The first time an event is added, we need to calculate
@@ -1 +1 @@
1
- {"version":3,"file":"eventDataBatch.js","sourceRoot":"","sources":["../../src/eventDataBatch.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAa,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAsB,OAAO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,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { EventData, toRheaMessage } from \"./eventData\";\nimport { ConnectionContext } from \"./connectionContext\";\nimport { MessageAnnotations, message, Message as RheaMessage } from \"rhea-promise\";\nimport { throwTypeErrorIfParameterMissing } from \"./util/error\";\nimport { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { Span, SpanContext } from \"@azure/core-tracing\";\nimport { instrumentEventData } from \"./diagnostics/instrumentEventData\";\nimport { convertTryAddOptionsForCompatibility } from \"./diagnostics/tracing\";\nimport { isDefined, isObjectWithProperties } from \"./util/typeGuards\";\nimport { OperationTracingOptions } from \"@azure/core-tracing\";\n\n/**\n * The amount of bytes to reserve as overhead for a small message.\n */\nconst smallMessageOverhead = 5;\n/**\n * The amount of bytes to reserve as overhead for a large message.\n */\nconst largeMessageOverhead = 8;\n/**\n * The maximum number of bytes that a message may be to be considered small.\n */\nconst smallMessageMaxBytes = 255;\n\n/**\n * Checks if the provided eventDataBatch is an instance of `EventDataBatch`.\n * @param eventDataBatch - The instance of `EventDataBatch` to verify.\n * @internal\n */\nexport function isEventDataBatch(eventDataBatch: unknown): eventDataBatch is EventDataBatch {\n return (\n isObjectWithProperties(eventDataBatch, [\"count\", \"sizeInBytes\", \"tryAdd\"]) &&\n typeof eventDataBatch.tryAdd === \"function\" &&\n typeof eventDataBatch.count === \"number\" &&\n typeof eventDataBatch.sizeInBytes === \"number\"\n );\n}\n\n/**\n * Options to configure the behavior of the `tryAdd` method on the `EventDataBatch` class.\n */\nexport interface TryAddOptions {\n /**\n * The options to use when creating Spans for tracing.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * @deprecated Tracing options have been moved to the `tracingOptions` property.\n */\n parentSpan?: Span | SpanContext;\n}\n\n/**\n * An interface representing a batch of events which can be used to send events to Event Hub.\n *\n * To create the batch, use the `createBatch()` method on the `EventHubProducerClient`.\n * To send the batch, use the `sendBatch()` method on the same client.\n * To fill the batch, use the `tryAdd()` method on the batch itself.\n *\n */\nexport interface EventDataBatch {\n /**\n * A value that is hashed and used by the Azure Event Hubs service to determine the partition to\n * which the events are sent. Use the `createBatch()` method on the `EventHubProducerClient` to\n * set the partitionKey.\n * @readonly\n * @internal\n */\n readonly partitionKey?: string;\n\n /**\n * Id of the partition to which the batch of events are sent. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the partitionId.\n * @readonly\n * @internal\n */\n readonly partitionId?: string;\n\n /**\n * Size of the batch in bytes after the events added to it have been encoded into a single AMQP\n * message.\n * @readonly\n */\n readonly sizeInBytes: number;\n\n /**\n * Number of events added to the batch.\n * @readonly\n */\n readonly count: number;\n\n /**\n * The maximum size of the batch, in bytes. The `tryAdd` function on the batch will return `false`\n * if the event being added causes the size of the batch to exceed this limit. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the maxSizeInBytes.\n * @readonly\n */\n readonly maxSizeInBytes: number;\n\n /**\n * Adds an event to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object or AmqpAnnotatedMessage.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n tryAdd(eventData: EventData | AmqpAnnotatedMessage, options?: TryAddOptions): boolean;\n\n /**\n * The AMQP message containing encoded events that were added to the batch.\n * Used internally by the `sendBatch()` method on the `EventHubProducerClient`.\n * This is not meant for the user to use directly.\n *\n * @internal\n */\n _generateMessage(): Buffer;\n\n /**\n * Gets the \"message\" span contexts that were created when adding events to the batch.\n * Used internally by the `sendBatch()` method to set up the right spans in traces if tracing is enabled.\n * @internal\n */\n readonly _messageSpanContexts: SpanContext[];\n}\n\n/**\n * An internal class representing a batch of events which can be used to send events to Event Hub.\n *\n * @internal\n */\nexport class EventDataBatchImpl implements EventDataBatch {\n /**\n * Describes the amqp connection context for the Client.\n */\n private _context: ConnectionContext;\n /**\n * The Id of the partition to which the batch is expected to be sent to.\n * Specifying this will throw an error if the batch was created using a `paritionKey`.\n */\n private _partitionId?: string;\n /**\n * A value that is hashed to produce a partition assignment.\n * It guarantees that messages with the same partitionKey end up in the same partition.\n * Specifying this will throw an error if the batch was created using a `paritionId`.\n */\n private _partitionKey?: string;\n /**\n * The maximum size allowed for the batch.\n */\n private _maxSizeInBytes: number;\n /**\n * Current size of the batch in bytes.\n */\n private _sizeInBytes: number;\n /**\n * Encoded amqp messages.\n */\n private _encodedMessages: Buffer[] = [];\n /**\n * Number of events in the batch.\n */\n private _count: number;\n /**\n * List of 'message' span contexts.\n */\n private _spanContexts: SpanContext[] = [];\n /**\n * The message annotations to apply on the batch envelope.\n * This will reflect the message annotations on the first event\n * that was added to the batch.\n * A common annotation is the partition key.\n */\n private _batchAnnotations?: MessageAnnotations;\n\n /**\n * EventDataBatch should not be constructed using `new EventDataBatch()`\n * Use the `createBatch()` method on your `EventHubProducer` instead.\n * @internal\n */\n constructor(\n context: ConnectionContext,\n maxSizeInBytes: number,\n partitionKey?: string,\n partitionId?: string\n ) {\n this._context = context;\n this._maxSizeInBytes = maxSizeInBytes;\n this._partitionKey = isDefined(partitionKey) ? String(partitionKey) : partitionKey;\n this._partitionId = isDefined(partitionId) ? String(partitionId) : partitionId;\n this._sizeInBytes = 0;\n this._count = 0;\n }\n\n /**\n * The maximum size of the batch, in bytes.\n * @readonly\n */\n get maxSizeInBytes(): number {\n return this._maxSizeInBytes;\n }\n\n /**\n * The partitionKey set during `EventDataBatch` creation. This value is hashed to\n * produce a partition assignment when the producer is created without a `partitionId`\n * @readonly\n */\n get partitionKey(): string | undefined {\n return this._partitionKey;\n }\n\n /**\n * The partitionId set during `EventDataBatch` creation.\n * If this value is set then partitionKey can not be set.\n * @readonly\n */\n get partitionId(): string | undefined {\n return this._partitionId;\n }\n\n /**\n * Size of the `EventDataBatch` instance after the events added to it have been\n * encoded into a single AMQP message.\n * @readonly\n */\n get sizeInBytes(): number {\n return this._sizeInBytes;\n }\n\n /**\n * Number of events in the `EventDataBatch` instance.\n * @readonly\n */\n get count(): number {\n return this._count;\n }\n\n /**\n * Gets the \"message\" span contexts that were created when adding events to the batch.\n * @internal\n */\n get _messageSpanContexts(): SpanContext[] {\n return this._spanContexts;\n }\n\n /**\n * Generates an AMQP message that contains the provided encoded events and annotations.\n * @param encodedEvents - The already encoded events to include in the AMQP batch.\n * @param annotations - The message annotations to set on the batch.\n */\n private _generateBatch(encodedEvents: Buffer[], annotations?: MessageAnnotations): Buffer {\n const batchEnvelope: RheaMessage = {\n body: message.data_sections(encodedEvents)\n };\n if (annotations) {\n batchEnvelope.message_annotations = annotations;\n }\n return message.encode(batchEnvelope);\n }\n\n /**\n * Generates the single AMQP message which is the result of encoding all the events\n * added into the `EventDataBatch` instance.\n *\n * This is not meant for the user to use directly.\n *\n * When the `EventDataBatch` instance is passed to the `send()` method on the `EventHubProducer`,\n * this single batched AMQP message is what gets sent over the wire to the service.\n * @readonly\n */\n _generateMessage(): Buffer {\n return this._generateBatch(this._encodedMessages, this._batchAnnotations);\n }\n\n /**\n * Tries to add an event data to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n public tryAdd(eventData: EventData | AmqpAnnotatedMessage, options: TryAddOptions = {}): boolean {\n throwTypeErrorIfParameterMissing(this._context.connectionId, \"tryAdd\", \"eventData\", eventData);\n options = convertTryAddOptionsForCompatibility(options);\n\n const { entityPath, host } = this._context.config;\n const { event: instrumentedEvent, spanContext } = instrumentEventData(\n eventData,\n options,\n entityPath,\n host\n );\n\n // Convert EventData to RheaMessage.\n const amqpMessage = toRheaMessage(instrumentedEvent, this._partitionKey);\n const encodedMessage = message.encode(amqpMessage);\n\n let currentSize = this._sizeInBytes;\n // The first time an event is added, we need to calculate\n // the overhead of creating an AMQP batch, including the\n // message_annotations that are taken from the 1st message.\n if (this.count === 0) {\n if (amqpMessage.message_annotations) {\n this._batchAnnotations = amqpMessage.message_annotations;\n }\n\n // Figure out the overhead of creating a batch by generating an empty batch\n // with the expected batch annotations.\n currentSize += this._generateBatch([], this._batchAnnotations).length;\n }\n\n const messageSize = encodedMessage.length;\n const messageOverhead =\n messageSize <= smallMessageMaxBytes ? smallMessageOverhead : largeMessageOverhead;\n currentSize += messageSize + messageOverhead;\n\n // Check if the size of the batch exceeds the maximum allowed size\n // once we add the new event to it.\n if (currentSize > this._maxSizeInBytes) {\n return false;\n }\n\n // The event will fit in the batch, so it is now safe to store it.\n this._encodedMessages.push(encodedMessage);\n if (spanContext) {\n this._spanContexts.push(spanContext);\n }\n\n this._sizeInBytes = currentSize;\n this._count++;\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"eventDataBatch.js","sourceRoot":"","sources":["../../src/eventDataBatch.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAa,sBAAsB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,EAAsB,OAAO,EAA0B,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAGhE,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC9F,OAAO,EAAE,oCAAoC,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAGtE;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B;;GAEG;AACH,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,cAAuB;IACtD,OAAO,CACL,sBAAs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Licensed under the MIT license.\n\nimport { EventData, isAmqpAnnotatedMessage, toRheaMessage } from \"./eventData\";\nimport { ConnectionContext } from \"./connectionContext\";\nimport { MessageAnnotations, message, Message as RheaMessage } from \"rhea-promise\";\nimport { throwTypeErrorIfParameterMissing } from \"./util/error\";\nimport { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { Span, SpanContext } from \"@azure/core-tracing\";\nimport { TRACEPARENT_PROPERTY, instrumentEventData } from \"./diagnostics/instrumentEventData\";\nimport { convertTryAddOptionsForCompatibility, createMessageSpan } from \"./diagnostics/tracing\";\nimport { isDefined, isObjectWithProperties } from \"./util/typeGuards\";\nimport { OperationTracingOptions } from \"@azure/core-tracing\";\n\n/**\n * The amount of bytes to reserve as overhead for a small message.\n */\nconst smallMessageOverhead = 5;\n/**\n * The amount of bytes to reserve as overhead for a large message.\n */\nconst largeMessageOverhead = 8;\n/**\n * The maximum number of bytes that a message may be to be considered small.\n */\nconst smallMessageMaxBytes = 255;\n\n/**\n * Checks if the provided eventDataBatch is an instance of `EventDataBatch`.\n * @param eventDataBatch - The instance of `EventDataBatch` to verify.\n * @internal\n */\nexport function isEventDataBatch(eventDataBatch: unknown): eventDataBatch is EventDataBatch {\n return (\n isObjectWithProperties(eventDataBatch, [\"count\", \"sizeInBytes\", \"tryAdd\"]) &&\n typeof eventDataBatch.tryAdd === \"function\" &&\n typeof eventDataBatch.count === \"number\" &&\n typeof eventDataBatch.sizeInBytes === \"number\"\n );\n}\n\n/**\n * Options to configure the behavior of the `tryAdd` method on the `EventDataBatch` class.\n */\nexport interface TryAddOptions {\n /**\n * The options to use when creating Spans for tracing.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * @deprecated Tracing options have been moved to the `tracingOptions` property.\n */\n parentSpan?: Span | SpanContext;\n}\n\n/**\n * An interface representing a batch of events which can be used to send events to Event Hub.\n *\n * To create the batch, use the `createBatch()` method on the `EventHubProducerClient`.\n * To send the batch, use the `sendBatch()` method on the same client.\n * To fill the batch, use the `tryAdd()` method on the batch itself.\n *\n */\nexport interface EventDataBatch {\n /**\n * A value that is hashed and used by the Azure Event Hubs service to determine the partition to\n * which the events are sent. Use the `createBatch()` method on the `EventHubProducerClient` to\n * set the partitionKey.\n * @readonly\n * @internal\n */\n readonly partitionKey?: string;\n\n /**\n * Id of the partition to which the batch of events are sent. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the partitionId.\n * @readonly\n * @internal\n */\n readonly partitionId?: string;\n\n /**\n * Size of the batch in bytes after the events added to it have been encoded into a single AMQP\n * message.\n * @readonly\n */\n readonly sizeInBytes: number;\n\n /**\n * Number of events added to the batch.\n * @readonly\n */\n readonly count: number;\n\n /**\n * The maximum size of the batch, in bytes. The `tryAdd` function on the batch will return `false`\n * if the event being added causes the size of the batch to exceed this limit. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the maxSizeInBytes.\n * @readonly\n */\n readonly maxSizeInBytes: number;\n\n /**\n * Adds an event to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object or AmqpAnnotatedMessage.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n tryAdd(eventData: EventData | AmqpAnnotatedMessage, options?: TryAddOptions): boolean;\n\n /**\n * The AMQP message containing encoded events that were added to the batch.\n * Used internally by the `sendBatch()` method on the `EventHubProducerClient`.\n * This is not meant for the user to use directly.\n *\n * @internal\n */\n _generateMessage(): Buffer;\n\n /**\n * Gets the \"message\" span contexts that were created when adding events to the batch.\n * Used internally by the `sendBatch()` method to set up the right spans in traces if tracing is enabled.\n * @internal\n */\n readonly _messageSpanContexts: SpanContext[];\n}\n\n/**\n * An internal class representing a batch of events which can be used to send events to Event Hub.\n *\n * @internal\n */\nexport class EventDataBatchImpl implements EventDataBatch {\n /**\n * Describes the amqp connection context for the Client.\n */\n private _context: ConnectionContext;\n /**\n * The Id of the partition to which the batch is expected to be sent to.\n * Specifying this will throw an error if the batch was created using a `paritionKey`.\n */\n private _partitionId?: string;\n /**\n * A value that is hashed to produce a partition assignment.\n * It guarantees that messages with the same partitionKey end up in the same partition.\n * Specifying this will throw an error if the batch was created using a `paritionId`.\n */\n private _partitionKey?: string;\n /**\n * The maximum size allowed for the batch.\n */\n private _maxSizeInBytes: number;\n /**\n * Current size of the batch in bytes.\n */\n private _sizeInBytes: number;\n /**\n * Encoded amqp messages.\n */\n private _encodedMessages: Buffer[] = [];\n /**\n * Number of events in the batch.\n */\n private _count: number;\n /**\n * List of 'message' span contexts.\n */\n private _spanContexts: SpanContext[] = [];\n /**\n * The message annotations to apply on the batch envelope.\n * This will reflect the message annotations on the first event\n * that was added to the batch.\n * A common annotation is the partition key.\n */\n private _batchAnnotations?: MessageAnnotations;\n\n /**\n * EventDataBatch should not be constructed using `new EventDataBatch()`\n * Use the `createBatch()` method on your `EventHubProducer` instead.\n * @internal\n */\n constructor(\n context: ConnectionContext,\n maxSizeInBytes: number,\n partitionKey?: string,\n partitionId?: string\n ) {\n this._context = context;\n this._maxSizeInBytes = maxSizeInBytes;\n this._partitionKey = isDefined(partitionKey) ? String(partitionKey) : partitionKey;\n this._partitionId = isDefined(partitionId) ? String(partitionId) : partitionId;\n this._sizeInBytes = 0;\n this._count = 0;\n }\n\n /**\n * The maximum size of the batch, in bytes.\n * @readonly\n */\n get maxSizeInBytes(): number {\n return this._maxSizeInBytes;\n }\n\n /**\n * The partitionKey set during `EventDataBatch` creation. This value is hashed to\n * produce a partition assignment when the producer is created without a `partitionId`\n * @readonly\n */\n get partitionKey(): string | undefined {\n return this._partitionKey;\n }\n\n /**\n * The partitionId set during `EventDataBatch` creation.\n * If this value is set then partitionKey can not be set.\n * @readonly\n */\n get partitionId(): string | undefined {\n return this._partitionId;\n }\n\n /**\n * Size of the `EventDataBatch` instance after the events added to it have been\n * encoded into a single AMQP message.\n * @readonly\n */\n get sizeInBytes(): number {\n return this._sizeInBytes;\n }\n\n /**\n * Number of events in the `EventDataBatch` instance.\n * @readonly\n */\n get count(): number {\n return this._count;\n }\n\n /**\n * Gets the \"message\" span contexts that were created when adding events to the batch.\n * @internal\n */\n get _messageSpanContexts(): SpanContext[] {\n return this._spanContexts;\n }\n\n /**\n * Generates an AMQP message that contains the provided encoded events and annotations.\n * @param encodedEvents - The already encoded events to include in the AMQP batch.\n * @param annotations - The message annotations to set on the batch.\n */\n private _generateBatch(encodedEvents: Buffer[], annotations?: MessageAnnotations): Buffer {\n const batchEnvelope: RheaMessage = {\n body: message.data_sections(encodedEvents)\n };\n if (annotations) {\n batchEnvelope.message_annotations = annotations;\n }\n return message.encode(batchEnvelope);\n }\n\n /**\n * Generates the single AMQP message which is the result of encoding all the events\n * added into the `EventDataBatch` instance.\n *\n * This is not meant for the user to use directly.\n *\n * When the `EventDataBatch` instance is passed to the `send()` method on the `EventHubProducer`,\n * this single batched AMQP message is what gets sent over the wire to the service.\n * @readonly\n */\n _generateMessage(): Buffer {\n return this._generateBatch(this._encodedMessages, this._batchAnnotations);\n }\n\n /**\n * Tries to add an event data to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n public tryAdd(eventData: EventData | AmqpAnnotatedMessage, options: TryAddOptions = {}): boolean {\n throwTypeErrorIfParameterMissing(this._context.connectionId, \"tryAdd\", \"eventData\", eventData);\n options = convertTryAddOptionsForCompatibility(options);\n\n // check if the event has already been instrumented\n const previouslyInstrumented = Boolean(\n (isAmqpAnnotatedMessage(eventData)\n ? eventData.applicationProperties\n : eventData.properties)?.[TRACEPARENT_PROPERTY] // Event Data maps properties to applicationProperties.\n );\n let spanContext: SpanContext | undefined;\n if (!previouslyInstrumented) {\n const { span: messageSpan } = createMessageSpan(options, this._context.config);\n eventData = instrumentEventData(eventData, messageSpan);\n spanContext = messageSpan.spanContext();\n messageSpan.end();\n }\n\n // Convert EventData to RheaMessage.\n const amqpMessage = toRheaMessage(eventData, this._partitionKey);\n const encodedMessage = message.encode(amqpMessage);\n\n let currentSize = this._sizeInBytes;\n // The first time an event is added, we need to calculate\n // the overhead of creating an AMQP batch, including the\n // message_annotations that are taken from the 1st message.\n if (this.count === 0) {\n if (amqpMessage.message_annotations) {\n this._batchAnnotations = amqpMessage.message_annotations;\n }\n\n // Figure out the overhead of creating a batch by generating an empty batch\n // with the expected batch annotations.\n currentSize += this._generateBatch([], this._batchAnnotations).length;\n }\n\n const messageSize = encodedMessage.length;\n const messageOverhead =\n messageSize <= smallMessageMaxBytes ? smallMessageOverhead : largeMessageOverhead;\n currentSize += messageSize + messageOverhead;\n\n // Check if the size of the batch exceeds the maximum allowed size\n // once we add the new event to it.\n if (currentSize > this._maxSizeInBytes) {\n return false;\n }\n\n // The event will fit in the batch, so it is now safe to store it.\n this._encodedMessages.push(encodedMessage);\n if (spanContext) {\n this._spanContexts.push(spanContext);\n }\n\n this._sizeInBytes = currentSize;\n this._count++;\n return true;\n }\n}\n"]}
@@ -2,7 +2,8 @@
2
2
  // Licensed under the MIT license.
3
3
  import { SpanStatusCode, SpanKind } from "@azure/core-tracing";
4
4
  import { createConnectionContext } from "./connectionContext";
5
- import { instrumentEventData } from "./diagnostics/instrumentEventData";
5
+ import { instrumentEventData, TRACEPARENT_PROPERTY } from "./diagnostics/instrumentEventData";
6
+ import { createMessageSpan } from "./diagnostics/tracing";
6
7
  import { EventDataBatchImpl, isEventDataBatch } from "./eventDataBatch";
7
8
  import { EventHubSender } from "./eventHubSender";
8
9
  import { logErrorStackTrace, logger } from "./log";
@@ -138,7 +139,15 @@ export class EventHubProducerClient {
138
139
  partitionId = expectedOptions.partitionId;
139
140
  partitionKey = expectedOptions.partitionKey;
140
141
  for (let i = 0; i < batch.length; i++) {
141
- batch[i] = instrumentEventData(batch[i], options, this._context.config.entityPath, this._context.config.host).event;
142
+ const event = batch[i];
143
+ if (!event.properties || !event.properties[TRACEPARENT_PROPERTY]) {
144
+ const { span: messageSpan } = createMessageSpan(options, this._context.config);
145
+ // since these message spans are created from same context as the send span,
146
+ // these message spans don't need to be linked.
147
+ // replace the original event with the instrumented one
148
+ batch[i] = instrumentEventData(batch[i], messageSpan);
149
+ messageSpan.end();
150
+ }
142
151
  }
143
152
  }
144
153
  if (isDefined(partitionId) && isDefined(partitionKey)) {
@@ -1 +1 @@
1
- {"version":3,"file":"eventHubProducerClient.js","sourceRoot":"","sources":["../../src/eventHubProducerClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,cAAc,EAA2B,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACxF,OAAO,EAAqB,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE,OAAO,EAAkB,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAUnD,OAAO,EAAE,4BAA4B,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,sBAAsB;IAoFjC,YACE,0CAAkD,EAClD,sBAAuD,EACvD,oBAIyB,EACzB,QAAgC,CAAC,yDAAyD;;QAE1F,IAAI,CAAC,QAAQ,GAAG,uBAAuB,CACrC,0CAA0C,EAC1C,sBAAsB,EACtB,oBAAoB,EACpB,QAAQ,CACT,CAAC;QACF,IAAI,OAAO,sBAAsB,KAAK,QAAQ,EAAE;YAC9C,IAAI,CAAC,cAAc,GAAG,sBAAsB,IAAI,EAAE,CAAC;SACpD;aAAM,IAAI,CAAC,YAAY,C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AkC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ;aACjB,iBAAkB,CAAC,qBAAqB,iCACpC,OAAO,KACV,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,YAAY,IAC9C;aACD,IAAI,CAAC,CAAC,kBAAkB,EAAE,EAAE;YAC3B,OAAO,kBAAkB,CAAC,YAAY,CAAC;QACzC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;OAOG;IACH,sBAAsB,CACpB,WAAmB,EACnB,UAAyC,EAAE;QAE3C,OAAO,IAAI,CAAC,QAAQ,CAAC,iBAAkB,CAAC,sBAAsB,CAAC,WAAW,kCACrE,OAAO,KACV,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,YAAY,IAC9C,CAAC;IACL,CAAC;IAEO,eAAe,CACrB,gBAAkC,EAClC,qBAAoC,EAAE;QAEtC,MAAM,KAAK,GAAW,kBAAkB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACvD,OAAO;gBACL,OAAO;aACR,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,MAAM,EAAE,IAAI,EAAE,GAAG,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YAClF,IAAI,EAAE,QAAQ,CAAC,MAAM;YACrB,KAAK;SACN,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { SpanStatusCode, Link, Span, SpanContext, SpanKind } from \"@azure/core-tracing\";\nimport { ConnectionContext, createConnectionContext } from \"./connectionContext\";\nimport { instrumentEventData } from \"./diagnostics/instrumentEventData\";\nimport { EventData } from \"./eventData\";\nimport { EventDataBatch, EventDataBatchImpl, isEventDataBatch } from \"./eventDataBatch\";\nimport { EventHubSender } from \"./eventHubSender\";\nimport { logErrorStackTrace, logger } from \"./log\";\nimport { EventHubProperties, PartitionProperties } from \"./managementClient\";\nimport {\n CreateBatchOptions,\n EventHubClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n SendBatchOptions\n} from \"./models/public\";\nimport { throwErrorIfConnectionClosed, throwTypeErrorIfParameterMissing } from \"./util/error\";\nimport { isCredential, isDefined } from \"./util/typeGuards\";\nimport { OperationOptions } from \"./util/operationOptions\";\nimport { createEventHubSpan } from \"./diagnostics/tracing\";\n\n/**\n * The `EventHubProducerClient` class is used to send events to an Event Hub.\n *\n * There are multiple ways to create an `EventHubProducerClient`\n * - Use the connection string from the SAS policy created for your Event Hub instance.\n * - Use the connection string from the SAS policy created for your Event Hub namespace,\n * and the name of the Event Hub instance\n * - Use the full namespace like `<yournamespace>.servicebus.windows.net`, and a credentials object.\n *\n * Optionally, you can also pass an options bag to configure the retry policy or proxy settings.\n *\n */\nexport class EventHubProducerClient {\n /**\n * Describes the amqp connection context for the client.\n */\n private _context: ConnectionContext;\n\n /**\n * The options passed by the user when creating the EventHubClient instance.\n */\n private _clientOptions: EventHubClientOptions;\n /**\n * Map of partitionId to senders\n */\n private _sendersMap: Map<string, EventHubSender>;\n /**\n * @readonly\n * The name of the Event Hub instance for which this client is created.\n */\n get eventHubName(): string {\n return this._context.config.entityPath;\n }\n\n /**\n * @readonly\n * The fully qualified namespace of the Event Hub instance for which this client is created.\n * This is likely to be similar to <yournamespace>.servicebus.windows.net.\n */\n get fullyQualifiedNamespace(): string {\n return this._context.config.host;\n }\n\n /**\n * The `EventHubProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(connectionString: string, options?: EventHubClientOptions); // eslint-disable-line @azure/azure-sdk/ts-naming-options\n /**\n * The `EventHubProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(connectionString: string, eventHubName: string, options?: EventHubClientOptions); // eslint-disable-line @azure/azure-sdk/ts-naming-options\n /**\n * The `EventHubProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See &commat;azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessKeyName`\n * and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively\n * in `AzureNamedKeyCredential`.\n * Use the `AzureSASCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options?: EventHubClientOptions // eslint-disable-line @azure/azure-sdk/ts-naming-options\n );\n constructor(\n fullyQualifiedNamespaceOrConnectionString1: string,\n eventHubNameOrOptions2?: string | EventHubClientOptions,\n credentialOrOptions3?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubClientOptions,\n options4?: EventHubClientOptions // eslint-disable-line @azure/azure-sdk/ts-naming-options\n ) {\n this._context = createConnectionContext(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n credentialOrOptions3,\n options4\n );\n if (typeof eventHubNameOrOptions2 !== \"string\") {\n this._clientOptions = eventHubNameOrOptions2 || {};\n } else if (!isCredential(credentialOrOptions3)) {\n this._clientOptions = credentialOrOptions3 || {};\n } else {\n this._clientOptions = options4 || {};\n }\n\n this._sendersMap = new Map();\n }\n\n /**\n * Creates an instance of `EventDataBatch` to which one can add events until the maximum supported size is reached.\n * The batch can be passed to the {@link sendBatch} method of the `EventHubProducerClient` to be sent to Azure Event Hubs.\n *\n * Example usage:\n * ```ts\n * const client = new EventHubProducerClient(connectionString);\n * let batch = await client.createBatch();\n * for (let i = 0; i < messages.length; i++) {\n * if (!batch.tryAdd(messages[i])) {\n * await client.sendBatch(batch);\n * batch = await client.createBatch();\n * if (!batch.tryAdd(messages[i])) {\n * throw new Error(\"Message too big to fit\")\n * }\n * if (i === messages.length - 1) {\n * await client.sendBatch(batch);\n * }\n * }\n * }\n * ```\n *\n * @param options - Configures the behavior of the batch.\n * - `partitionKey` : A value that is hashed and used by the Azure Event Hubs service to determine the partition to which\n * the events need to be sent.\n * - `partitionId` : Id of the partition to which the batch of events need to be sent.\n * - `maxSizeInBytes`: The upper limit for the size of batch. The `tryAdd` function will return `false` after this limit is reached.\n * - `abortSignal` : A signal the request to cancel the operation.\n * @returns Promise<EventDataBatch>\n * @throws Error if both `partitionId` and `partitionKey` are set in the options.\n * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal in the options.\n */\n async createBatch(options: CreateBatchOptions = {}): Promise<EventDataBatch> {\n throwErrorIfConnectionClosed(this._context);\n\n if (isDefined(options.partitionId) && isDefined(options.partitionKey)) {\n throw new Error(\"partitionId and partitionKey cannot both be set when creating a batch\");\n }\n\n let sender = this._sendersMap.get(\"\");\n if (!sender) {\n sender = EventHubSender.create(this._context);\n this._sendersMap.set(\"\", sender);\n }\n\n let maxMessageSize = await sender.getMaxMessageSize({\n retryOptions: this._clientOptions.retryOptions,\n abortSignal: options.abortSignal\n });\n\n if (options.maxSizeInBytes) {\n if (options.maxSizeInBytes > maxMessageSize) {\n const error = new Error(\n `Max message size (${options.maxSizeInBytes} bytes) is greater than maximum message size (${maxMessageSize} bytes) on the AMQP sender link.`\n );\n logger.warning(`[${this._context.connectionId}] ${error.message}`);\n logErrorStackTrace(error);\n throw error;\n }\n maxMessageSize = options.maxSizeInBytes;\n }\n return new EventDataBatchImpl(\n this._context,\n maxMessageSize,\n options.partitionKey,\n options.partitionId\n );\n }\n\n /**\n * Sends an array of events to the associated Event Hub.\n *\n * Example usage:\n * ```ts\n * const client = new EventHubProducerClient(connectionString);\n * await client.sendBatch(messages);\n * ```\n *\n * @param batch - An array of {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * events are sent to the associated Event Hub.\n * - `abortSignal` : A signal the request to cancel the send operation.\n * - `partitionId` : The partition this batch will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n *\n * @returns Promise<void>\n * @throws AbortError if the operation is cancelled via the abortSignal.\n * @throws MessagingError if an error is encountered while sending a message.\n * @throws Error if the underlying connection or sender has been closed.\n */\n async sendBatch(\n batch: EventData[] | AmqpAnnotatedMessage[],\n options?: SendBatchOptions\n ): Promise<void>;\n /**\n * Sends a batch of events to the associated Event Hub.\n *\n * Example usage:\n * ```ts\n * const client = new EventHubProducerClient(connectionString);\n * let batch = await client.createBatch();\n * for (let i = 0; i < messages.length; i++) {\n * if (!batch.tryAdd(messages[i])) {\n * await client.sendBatch(batch);\n * batch = await client.createBatch();\n * if (!batch.tryAdd(messages[i])) {\n * throw new Error(\"Message too big to fit\")\n * }\n * if (i === messages.length - 1) {\n * await client.sendBatch(batch);\n * }\n * }\n * }\n * ```\n * @param batch - A batch of events that you can create using the {@link createBatch} method.\n * @param options - A set of options that can be specified to influence the way in which\n * events are sent to the associated Event Hub.\n * - `abortSignal` : A signal the request to cancel the send operation.\n *\n * @returns Promise<void>\n * @throws AbortError if the operation is cancelled via the abortSignal.\n * @throws MessagingError if an error is encountered while sending a message.\n * @throws Error if the underlying connection or sender has been closed.\n */\n async sendBatch(batch: EventDataBatch, options?: OperationOptions): Promise<void>; // eslint-disable-line @azure/azure-sdk/ts-naming-options\n async sendBatch(\n batch: EventDataBatch | EventData[],\n options: SendBatchOptions | OperationOptions = {}\n ): Promise<void> {\n throwErrorIfConnectionClosed(this._context);\n throwTypeErrorIfParameterMissing(this._context.connectionId, \"sendBatch\", \"batch\", batch);\n\n let partitionId: string | undefined;\n let partitionKey: string | undefined;\n\n // link message span contexts\n let spanContextsToLink: SpanContext[] = [];\n\n if (isEventDataBatch(batch)) {\n // For batches, partitionId and partitionKey would be set on the batch.\n partitionId = batch.partitionId;\n partitionKey = batch.partitionKey;\n const unexpectedOptions = options as SendBatchOptions;\n if (unexpectedOptions.partitionKey && partitionKey !== unexpectedOptions.partitionKey) {\n throw new Error(\n `The partitionKey (${unexpectedOptions.partitionKey}) set on sendBatch does not match the partitionKey (${partitionKey}) set when creating the batch.`\n );\n }\n if (unexpectedOptions.partitionId && unexpectedOptions.partitionId !== partitionId) {\n throw new Error(\n `The partitionId (${unexpectedOptions.partitionId}) set on sendBatch does not match the partitionId (${partitionId}) set when creating the batch.`\n );\n }\n\n spanContextsToLink = batch._messageSpanContexts;\n } else {\n if (!Array.isArray(batch)) {\n batch = [batch];\n }\n\n // For arrays of events, partitionId and partitionKey would be set in the options.\n const expectedOptions = options as SendBatchOptions;\n partitionId = expectedOptions.partitionId;\n partitionKey = expectedOptions.partitionKey;\n\n for (let i = 0; i < batch.length; i++) {\n batch[i] = instrumentEventData(\n batch[i],\n options,\n this._context.config.entityPath,\n this._context.config.host\n ).event;\n }\n }\n if (isDefined(partitionId) && isDefined(partitionKey)) {\n throw new Error(\n `The partitionId (${partitionId}) and partitionKey (${partitionKey}) cannot both be specified.`\n );\n }\n\n if (isDefined(partitionId)) {\n partitionId = String(partitionId);\n }\n if (isDefined(partitionKey)) {\n partitionKey = String(partitionKey);\n }\n\n let sender = this._sendersMap.get(partitionId || \"\");\n if (!sender) {\n sender = EventHubSender.create(this._context, partitionId);\n this._sendersMap.set(partitionId || \"\", sender);\n }\n\n const sendSpan = this._createSendSpan(options, spanContextsToLink);\n\n try {\n const result = await sender.send(batch, {\n ...options,\n partitionId,\n partitionKey,\n retryOptions: this._clientOptions.retryOptions\n });\n sendSpan.setStatus({ code: SpanStatusCode.OK });\n return result;\n } catch (error) {\n sendSpan.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message\n });\n throw error;\n } finally {\n sendSpan.end();\n }\n }\n\n /**\n * Closes the AMQP connection to the Event Hub instance,\n * returning a promise that will be resolved when disconnection is completed.\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n async close(): Promise<void> {\n await this._context.close();\n\n for (const pair of this._sendersMap) {\n await pair[1].close();\n }\n this._sendersMap.clear();\n }\n\n /**\n * Provides the Event Hub runtime information.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the Event Hub instance.\n * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getEventHubProperties(options: GetEventHubPropertiesOptions = {}): Promise<EventHubProperties> {\n return this._context.managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions\n });\n }\n\n /**\n * Provides the id for each partition associated with the Event Hub.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with an Array of strings representing the id for\n * each partition associated with the Event Hub.\n * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._context\n .managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions\n })\n .then((eventHubProperties) => {\n return eventHubProperties.partitionIds;\n });\n }\n\n /**\n * Provides information about the state of the specified partition.\n * @param partitionId - The id of the partition for which information is required.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the state of the partition .\n * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionProperties(\n partitionId: string,\n options: GetPartitionPropertiesOptions = {}\n ): Promise<PartitionProperties> {\n return this._context.managementSession!.getPartitionProperties(partitionId, {\n ...options,\n retryOptions: this._clientOptions.retryOptions\n });\n }\n\n private _createSendSpan(\n operationOptions: OperationOptions,\n spanContextsToLink: SpanContext[] = []\n ): Span {\n const links: Link[] = spanContextsToLink.map((context) => {\n return {\n context\n };\n });\n\n const { span } = createEventHubSpan(\"send\", operationOptions, this._context.config, {\n kind: SpanKind.CLIENT,\n links\n });\n\n return span;\n }\n}\n"]}
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AO,KACV,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,YAAY,IAC9C,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,eAAe,CAAC,UAAkC,EAAE;QAClD,OAAO,IAAI,CAAC,QAAQ;aACjB,iBAAkB,CAAC,qBAAqB,iCACpC,OAAO,KACV,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,YAAY,IAC9C;aACD,IAAI,CAAC,CAAC,kBAAkB,EAAE,EAAE;YAC3B,OAAO,kBAAkB,CAAC,YAAY,CAAC;QACzC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;OAOG;IACH,sBAAsB,CACpB,WAAmB,EACnB,UAAyC,EAAE;QAE3C,OAAO,IAAI,CAAC,QAAQ,CAAC,iBAAkB,CAAC,sBAAsB,CAAC,WAAW,kCACrE,OAAO,KACV,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,YAAY,IAC9C,CAAC;IACL,CAAC;IAEO,eAAe,CACrB,gBAAkC,EAClC,qBAAoC,EAAE;QAEtC,MAAM,KAAK,GAAW,kBAAkB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACvD,OAAO;gBACL,OAAO;aACR,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,MAAM,EAAE,IAAI,EAAE,GAAG,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YAClF,IAAI,EAAE,QAAQ,CAAC,MAAM;YACrB,KAAK;SACN,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { SpanStatusCode, Link, Span, SpanContext, SpanKind } from \"@azure/core-tracing\";\nimport { ConnectionContext, createConnectionContext } from \"./connectionContext\";\nimport { instrumentEventData, TRACEPARENT_PROPERTY } from \"./diagnostics/instrumentEventData\";\nimport { createMessageSpan } from \"./diagnostics/tracing\";\nimport { EventData } from \"./eventData\";\nimport { EventDataBatch, EventDataBatchImpl, isEventDataBatch } from \"./eventDataBatch\";\nimport { EventHubSender } from \"./eventHubSender\";\nimport { logErrorStackTrace, logger } from \"./log\";\nimport { EventHubProperties, PartitionProperties } from \"./managementClient\";\nimport {\n CreateBatchOptions,\n EventHubClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n SendBatchOptions\n} from \"./models/public\";\nimport { throwErrorIfConnectionClosed, throwTypeErrorIfParameterMissing } from \"./util/error\";\nimport { isCredential, isDefined } from \"./util/typeGuards\";\nimport { OperationOptions } from \"./util/operationOptions\";\nimport { createEventHubSpan } from \"./diagnostics/tracing\";\n\n/**\n * The `EventHubProducerClient` class is used to send events to an Event Hub.\n *\n * There are multiple ways to create an `EventHubProducerClient`\n * - Use the connection string from the SAS policy created for your Event Hub instance.\n * - Use the connection string from the SAS policy created for your Event Hub namespace,\n * and the name of the Event Hub instance\n * - Use the full namespace like `<yournamespace>.servicebus.windows.net`, and a credentials object.\n *\n * Optionally, you can also pass an options bag to configure the retry policy or proxy settings.\n *\n */\nexport class EventHubProducerClient {\n /**\n * Describes the amqp connection context for the client.\n */\n private _context: ConnectionContext;\n\n /**\n * The options passed by the user when creating the EventHubClient instance.\n */\n private _clientOptions: EventHubClientOptions;\n /**\n * Map of partitionId to senders\n */\n private _sendersMap: Map<string, EventHubSender>;\n /**\n * @readonly\n * The name of the Event Hub instance for which this client is created.\n */\n get eventHubName(): string {\n return this._context.config.entityPath;\n }\n\n /**\n * @readonly\n * The fully qualified namespace of the Event Hub instance for which this client is created.\n * This is likely to be similar to <yournamespace>.servicebus.windows.net.\n */\n get fullyQualifiedNamespace(): string {\n return this._context.config.host;\n }\n\n /**\n * The `EventHubProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(connectionString: string, options?: EventHubClientOptions); // eslint-disable-line @azure/azure-sdk/ts-naming-options\n /**\n * The `EventHubProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(connectionString: string, eventHubName: string, options?: EventHubClientOptions); // eslint-disable-line @azure/azure-sdk/ts-naming-options\n /**\n * The `EventHubProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See &commat;azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessKeyName`\n * and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively\n * in `AzureNamedKeyCredential`.\n * Use the `AzureSASCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options?: EventHubClientOptions // eslint-disable-line @azure/azure-sdk/ts-naming-options\n );\n constructor(\n fullyQualifiedNamespaceOrConnectionString1: string,\n eventHubNameOrOptions2?: string | EventHubClientOptions,\n credentialOrOptions3?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubClientOptions,\n options4?: EventHubClientOptions // eslint-disable-line @azure/azure-sdk/ts-naming-options\n ) {\n this._context = createConnectionContext(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n credentialOrOptions3,\n options4\n );\n if (typeof eventHubNameOrOptions2 !== \"string\") {\n this._clientOptions = eventHubNameOrOptions2 || {};\n } else if (!isCredential(credentialOrOptions3)) {\n this._clientOptions = credentialOrOptions3 || {};\n } else {\n this._clientOptions = options4 || {};\n }\n\n this._sendersMap = new Map();\n }\n\n /**\n * Creates an instance of `EventDataBatch` to which one can add events until the maximum supported size is reached.\n * The batch can be passed to the {@link sendBatch} method of the `EventHubProducerClient` to be sent to Azure Event Hubs.\n *\n * Example usage:\n * ```ts\n * const client = new EventHubProducerClient(connectionString);\n * let batch = await client.createBatch();\n * for (let i = 0; i < messages.length; i++) {\n * if (!batch.tryAdd(messages[i])) {\n * await client.sendBatch(batch);\n * batch = await client.createBatch();\n * if (!batch.tryAdd(messages[i])) {\n * throw new Error(\"Message too big to fit\")\n * }\n * if (i === messages.length - 1) {\n * await client.sendBatch(batch);\n * }\n * }\n * }\n * ```\n *\n * @param options - Configures the behavior of the batch.\n * - `partitionKey` : A value that is hashed and used by the Azure Event Hubs service to determine the partition to which\n * the events need to be sent.\n * - `partitionId` : Id of the partition to which the batch of events need to be sent.\n * - `maxSizeInBytes`: The upper limit for the size of batch. The `tryAdd` function will return `false` after this limit is reached.\n * - `abortSignal` : A signal the request to cancel the operation.\n * @returns Promise<EventDataBatch>\n * @throws Error if both `partitionId` and `partitionKey` are set in the options.\n * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal in the options.\n */\n async createBatch(options: CreateBatchOptions = {}): Promise<EventDataBatch> {\n throwErrorIfConnectionClosed(this._context);\n\n if (isDefined(options.partitionId) && isDefined(options.partitionKey)) {\n throw new Error(\"partitionId and partitionKey cannot both be set when creating a batch\");\n }\n\n let sender = this._sendersMap.get(\"\");\n if (!sender) {\n sender = EventHubSender.create(this._context);\n this._sendersMap.set(\"\", sender);\n }\n\n let maxMessageSize = await sender.getMaxMessageSize({\n retryOptions: this._clientOptions.retryOptions,\n abortSignal: options.abortSignal\n });\n\n if (options.maxSizeInBytes) {\n if (options.maxSizeInBytes > maxMessageSize) {\n const error = new Error(\n `Max message size (${options.maxSizeInBytes} bytes) is greater than maximum message size (${maxMessageSize} bytes) on the AMQP sender link.`\n );\n logger.warning(`[${this._context.connectionId}] ${error.message}`);\n logErrorStackTrace(error);\n throw error;\n }\n maxMessageSize = options.maxSizeInBytes;\n }\n return new EventDataBatchImpl(\n this._context,\n maxMessageSize,\n options.partitionKey,\n options.partitionId\n );\n }\n\n /**\n * Sends an array of events to the associated Event Hub.\n *\n * Example usage:\n * ```ts\n * const client = new EventHubProducerClient(connectionString);\n * await client.sendBatch(messages);\n * ```\n *\n * @param batch - An array of {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * events are sent to the associated Event Hub.\n * - `abortSignal` : A signal the request to cancel the send operation.\n * - `partitionId` : The partition this batch will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n *\n * @returns Promise<void>\n * @throws AbortError if the operation is cancelled via the abortSignal.\n * @throws MessagingError if an error is encountered while sending a message.\n * @throws Error if the underlying connection or sender has been closed.\n */\n async sendBatch(\n batch: EventData[] | AmqpAnnotatedMessage[],\n options?: SendBatchOptions\n ): Promise<void>;\n /**\n * Sends a batch of events to the associated Event Hub.\n *\n * Example usage:\n * ```ts\n * const client = new EventHubProducerClient(connectionString);\n * let batch = await client.createBatch();\n * for (let i = 0; i < messages.length; i++) {\n * if (!batch.tryAdd(messages[i])) {\n * await client.sendBatch(batch);\n * batch = await client.createBatch();\n * if (!batch.tryAdd(messages[i])) {\n * throw new Error(\"Message too big to fit\")\n * }\n * if (i === messages.length - 1) {\n * await client.sendBatch(batch);\n * }\n * }\n * }\n * ```\n * @param batch - A batch of events that you can create using the {@link createBatch} method.\n * @param options - A set of options that can be specified to influence the way in which\n * events are sent to the associated Event Hub.\n * - `abortSignal` : A signal the request to cancel the send operation.\n *\n * @returns Promise<void>\n * @throws AbortError if the operation is cancelled via the abortSignal.\n * @throws MessagingError if an error is encountered while sending a message.\n * @throws Error if the underlying connection or sender has been closed.\n */\n async sendBatch(batch: EventDataBatch, options?: OperationOptions): Promise<void>; // eslint-disable-line @azure/azure-sdk/ts-naming-options\n async sendBatch(\n batch: EventDataBatch | EventData[],\n options: SendBatchOptions | OperationOptions = {}\n ): Promise<void> {\n throwErrorIfConnectionClosed(this._context);\n throwTypeErrorIfParameterMissing(this._context.connectionId, \"sendBatch\", \"batch\", batch);\n\n let partitionId: string | undefined;\n let partitionKey: string | undefined;\n\n // link message span contexts\n let spanContextsToLink: SpanContext[] = [];\n\n if (isEventDataBatch(batch)) {\n // For batches, partitionId and partitionKey would be set on the batch.\n partitionId = batch.partitionId;\n partitionKey = batch.partitionKey;\n const unexpectedOptions = options as SendBatchOptions;\n if (unexpectedOptions.partitionKey && partitionKey !== unexpectedOptions.partitionKey) {\n throw new Error(\n `The partitionKey (${unexpectedOptions.partitionKey}) set on sendBatch does not match the partitionKey (${partitionKey}) set when creating the batch.`\n );\n }\n if (unexpectedOptions.partitionId && unexpectedOptions.partitionId !== partitionId) {\n throw new Error(\n `The partitionId (${unexpectedOptions.partitionId}) set on sendBatch does not match the partitionId (${partitionId}) set when creating the batch.`\n );\n }\n\n spanContextsToLink = batch._messageSpanContexts;\n } else {\n if (!Array.isArray(batch)) {\n batch = [batch];\n }\n\n // For arrays of events, partitionId and partitionKey would be set in the options.\n const expectedOptions = options as SendBatchOptions;\n partitionId = expectedOptions.partitionId;\n partitionKey = expectedOptions.partitionKey;\n\n for (let i = 0; i < batch.length; i++) {\n const event = batch[i];\n if (!event.properties || !event.properties[TRACEPARENT_PROPERTY]) {\n const { span: messageSpan } = createMessageSpan(options, this._context.config);\n // since these message spans are created from same context as the send span,\n // these message spans don't need to be linked.\n // replace the original event with the instrumented one\n batch[i] = instrumentEventData(batch[i], messageSpan);\n messageSpan.end();\n }\n }\n }\n if (isDefined(partitionId) && isDefined(partitionKey)) {\n throw new Error(\n `The partitionId (${partitionId}) and partitionKey (${partitionKey}) cannot both be specified.`\n );\n }\n\n if (isDefined(partitionId)) {\n partitionId = String(partitionId);\n }\n if (isDefined(partitionKey)) {\n partitionKey = String(partitionKey);\n }\n\n let sender = this._sendersMap.get(partitionId || \"\");\n if (!sender) {\n sender = EventHubSender.create(this._context, partitionId);\n this._sendersMap.set(partitionId || \"\", sender);\n }\n\n const sendSpan = this._createSendSpan(options, spanContextsToLink);\n\n try {\n const result = await sender.send(batch, {\n ...options,\n partitionId,\n partitionKey,\n retryOptions: this._clientOptions.retryOptions\n });\n sendSpan.setStatus({ code: SpanStatusCode.OK });\n return result;\n } catch (error) {\n sendSpan.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message\n });\n throw error;\n } finally {\n sendSpan.end();\n }\n }\n\n /**\n * Closes the AMQP connection to the Event Hub instance,\n * returning a promise that will be resolved when disconnection is completed.\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n async close(): Promise<void> {\n await this._context.close();\n\n for (const pair of this._sendersMap) {\n await pair[1].close();\n }\n this._sendersMap.clear();\n }\n\n /**\n * Provides the Event Hub runtime information.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the Event Hub instance.\n * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getEventHubProperties(options: GetEventHubPropertiesOptions = {}): Promise<EventHubProperties> {\n return this._context.managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions\n });\n }\n\n /**\n * Provides the id for each partition associated with the Event Hub.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with an Array of strings representing the id for\n * each partition associated with the Event Hub.\n * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._context\n .managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions\n })\n .then((eventHubProperties) => {\n return eventHubProperties.partitionIds;\n });\n }\n\n /**\n * Provides information about the state of the specified partition.\n * @param partitionId - The id of the partition for which information is required.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the state of the partition .\n * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionProperties(\n partitionId: string,\n options: GetPartitionPropertiesOptions = {}\n ): Promise<PartitionProperties> {\n return this._context.managementSession!.getPartitionProperties(partitionId, {\n ...options,\n retryOptions: this._clientOptions.retryOptions\n });\n }\n\n private _createSendSpan(\n operationOptions: OperationOptions,\n spanContextsToLink: SpanContext[] = []\n ): Span {\n const links: Link[] = spanContextsToLink.map((context) => {\n return {\n context\n };\n });\n\n const { span } = createEventHubSpan(\"send\", operationOptions, this._context.config, {\n kind: SpanKind.CLIENT,\n links\n });\n\n return span;\n }\n}\n"]}
@@ -2,7 +2,6 @@
2
2
  // Licensed under the MIT license.
3
3
  export { EventHubConsumerClient } from "./eventHubConsumerClient";
4
4
  export { EventHubProducerClient } from "./eventHubProducerClient";
5
- export { EventHubBufferedProducerClient } from "./eventHubBufferedProducerClient";
6
5
  export { latestEventPosition, earliestEventPosition } from "./eventPosition";
7
6
  export { CloseReason } from "./models/public";
8
7
  export { MessagingError, RetryMode } from "@azure/core-amqp";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAkBlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAEL,8BAA8B,EAM/B,MAAM,kCAAkC,CAAC;AAW1C,OAAO,EAAiB,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAK5F,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAgB,SAAS,EAAoB,MAAM,kBAAkB,CAAC;AAE7F,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,6BAA6B,EAE9B,MAAM,8BAA8B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/// <reference lib=\"esnext.asynciterable\" />\n\nexport { EventData, ReceivedEventData } from \"./eventData\";\nexport { WebSocketImpl } from \"rhea-promise\";\nexport { LastEnqueuedEventProperties } from \"./eventHubReceiver\";\nexport { OperationOptions } from \"./util/operationOptions\";\nexport {\n EventHubClientOptions,\n EventHubConsumerClientOptions,\n LoadBalancingOptions,\n SendBatchOptions,\n CreateBatchOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n GetEventHubPropertiesOptions\n} from \"./models/public\";\nexport { EventHubConsumerClient } from \"./eventHubConsumerClient\";\nexport { EventHubProducerClient } from \"./eventHubProducerClient\";\nexport {\n BufferedCloseOptions,\n EventHubBufferedProducerClient,\n EventHubBufferedProducerClientOptions,\n EnqueueEventOptions,\n BufferedFlushOptions,\n OnSendEventsErrorContext,\n OnSendEventsSuccessContext\n} from \"./eventHubBufferedProducerClient\";\nexport {\n SubscribeOptions,\n Subscription,\n SubscriptionEventHandlers,\n PartitionContext,\n ProcessErrorHandler,\n ProcessInitializeHandler,\n ProcessCloseHandler,\n ProcessEventsHandler\n} from \"./eventHubConsumerClientModels\";\nexport { EventPosition, latestEventPosition, earliestEventPosition } from \"./eventPosition\";\nexport { PartitionProperties, EventHubProperties } from \"./managementClient\";\nexport { EventDataBatch, TryAddOptions } from \"./eventDataBatch\";\nexport { Checkpoint } from \"./partitionProcessor\";\nexport { CheckpointStore, PartitionOwnership } from \"./eventProcessor\";\nexport { CloseReason } from \"./models/public\";\nexport { MessagingError, RetryOptions, RetryMode, WebSocketOptions } from \"@azure/core-amqp\";\nexport { TokenCredential } from \"@azure/core-auth\";\nexport { logger } from \"./log\";\nexport {\n parseEventHubConnectionString,\n EventHubConnectionStringProperties\n} from \"./util/connectionStringUtils\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAkBlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAWlE,OAAO,EAAiB,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAK5F,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAgB,SAAS,EAAoB,MAAM,kBAAkB,CAAC;AAE7F,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,6BAA6B,EAE9B,MAAM,8BAA8B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/// <reference lib=\"esnext.asynciterable\" />\n\nexport { EventData, ReceivedEventData } from \"./eventData\";\nexport { WebSocketImpl } from \"rhea-promise\";\nexport { LastEnqueuedEventProperties } from \"./eventHubReceiver\";\nexport { OperationOptions } from \"./util/operationOptions\";\nexport {\n EventHubClientOptions,\n EventHubConsumerClientOptions,\n LoadBalancingOptions,\n SendBatchOptions,\n CreateBatchOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n GetEventHubPropertiesOptions\n} from \"./models/public\";\nexport { EventHubConsumerClient } from \"./eventHubConsumerClient\";\nexport { EventHubProducerClient } from \"./eventHubProducerClient\";\nexport {\n SubscribeOptions,\n Subscription,\n SubscriptionEventHandlers,\n PartitionContext,\n ProcessErrorHandler,\n ProcessInitializeHandler,\n ProcessCloseHandler,\n ProcessEventsHandler\n} from \"./eventHubConsumerClientModels\";\nexport { EventPosition, latestEventPosition, earliestEventPosition } from \"./eventPosition\";\nexport { PartitionProperties, EventHubProperties } from \"./managementClient\";\nexport { EventDataBatch, TryAddOptions } from \"./eventDataBatch\";\nexport { Checkpoint } from \"./partitionProcessor\";\nexport { CheckpointStore, PartitionOwnership } from \"./eventProcessor\";\nexport { CloseReason } from \"./models/public\";\nexport { MessagingError, RetryOptions, RetryMode, WebSocketOptions } from \"@azure/core-amqp\";\nexport { TokenCredential } from \"@azure/core-auth\";\nexport { logger } from \"./log\";\nexport {\n parseEventHubConnectionString,\n EventHubConnectionStringProperties\n} from \"./util/connectionStringUtils\";\n"]}
@@ -5,6 +5,6 @@
5
5
  */
6
6
  export const packageJsonInfo = {
7
7
  name: "@azure/event-hubs",
8
- version: "5.7.0-beta.1"
8
+ version: "5.7.0"
9
9
  };
10
10
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/util/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,mBAAmB;IACzB,OAAO,EAAE,cAAc;CACxB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * @hidden\n */\nexport const packageJsonInfo = {\n name: \"@azure/event-hubs\",\n version: \"5.7.0-beta.1\"\n};\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/util/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,mBAAmB;IACzB,OAAO,EAAE,OAAO;CACjB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * @hidden\n */\nexport const packageJsonInfo = {\n name: \"@azure/event-hubs\",\n version: \"5.7.0\"\n};\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@azure/event-hubs",
3
3
  "sdk-type": "client",
4
- "version": "5.7.0-beta.1",
4
+ "version": "5.7.0",
5
5
  "description": "Azure Event Hubs SDK for JS.",
6
6
  "author": "Microsoft Corporation",
7
7
  "license": "MIT",
@@ -32,8 +32,7 @@
32
32
  }
33
33
  },
34
34
  "browser": {
35
- "./dist-esm/src/util/runtimeInfo.js": "./dist-esm/src/util/runtimeInfo.browser.js",
36
- "./dist-esm/test/public/utils/mockService.js": "./dist-esm/test/public/utils/mockService.browser.js"
35
+ "./dist-esm/src/util/runtimeInfo.js": "./dist-esm/src/util/runtimeInfo.browser.js"
37
36
  },
38
37
  "files": [
39
38
  "dist/",
@@ -50,27 +49,27 @@
50
49
  "build:samples": "echo Obsolete.",
51
50
  "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1",
52
51
  "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1",
53
- "build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1 && npm run generate-certs",
52
+ "build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
54
53
  "build:types": "downlevel-dts types/latest types/3.1",
55
- "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local && npm run build:types",
54
+ "build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local && npm run build:types",
56
55
  "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
57
56
  "clean": "rimraf dist dist-* types *.tgz *.log",
58
57
  "execute:samples": "dev-tool samples run samples-dev",
59
58
  "extract-api": "tsc -p . && api-extractor run --local",
60
59
  "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
61
- "generate-certs": "node ./scripts/generateCerts.js",
62
- "integration-test:browser": "cross-env TEST_TARGET=live DISABLE_MULTI_VERSION_TESTING=true karma start --single-run",
63
- "integration-test:node": "cross-env TEST_TARGET=live DISABLE_MULTI_VERSION_TESTING=true nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/**/*.spec.js\" \"dist-esm/test/internal/**/*.spec.js\"",
60
+ "integration-test:browser": "karma start --single-run",
61
+ "integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/**/*.spec.js\" \"dist-esm/test/internal/**/*.spec.js\"",
64
62
  "integration-test": "npm run integration-test:node && npm run integration-test:browser",
65
63
  "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
66
64
  "lint": "eslint package.json api-extractor.json src test --ext .ts",
67
65
  "pack": "npm pack 2>&1",
68
66
  "perf-test:node": "tsc -p . --module \"commonjs\" && node dist-esm/test/perf/track-2/index.spec.js",
67
+ "prebuild": "npm run clean",
69
68
  "test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
70
69
  "test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
71
70
  "test": "npm run build:test && npm run unit-test && npm run integration-test",
72
71
  "unit-test:browser": "echo skipped",
73
- "unit-test:node": "cross-env NODE_EXTRA_CA_CERTS=\"./certs/my-private-root-ca.crt.pem\" TEST_TARGET=mock DISABLE_MULTI_VERSION_TESTING=true nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/**/*.spec.js\" \"dist-esm/test/internal/**/*.spec.js\"",
72
+ "unit-test:node": "echo skipped",
74
73
  "unit-test": "npm run unit-test:node && npm run unit-test:browser",
75
74
  "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src"
76
75
  },
@@ -93,7 +92,6 @@
93
92
  },
94
93
  "skip": [
95
94
  "iothubConnectionString.js",
96
- "iothubConnectionStringWebsockets.js",
97
95
  "useWithIotHub.js",
98
96
  "usingAadAuth.js"
99
97
  ],
@@ -111,9 +109,9 @@
111
109
  "@azure/core-amqp": "^3.0.0",
112
110
  "@azure/core-asynciterator-polyfill": "^1.0.0",
113
111
  "@azure/core-auth": "^1.3.0",
114
- "@azure/core-tracing": "1.0.0-preview.13",
112
+ "@azure/core-tracing": "1.0.0-preview.12",
115
113
  "@azure/logger": "^1.0.0",
116
- "buffer": "^6.0.0",
114
+ "buffer": "^5.2.1",
117
115
  "is-buffer": "^2.0.3",
118
116
  "jssha": "^3.1.0",
119
117
  "process": "^0.11.10",
@@ -124,11 +122,9 @@
124
122
  "devDependencies": {
125
123
  "@azure/dev-tool": "^1.0.0",
126
124
  "@azure/eslint-plugin-azure-sdk": "^3.0.0",
127
- "@azure/identity": "^2.0.1",
128
- "@azure/mock-hub": "^1.0.0",
129
- "@azure/test-utils": "^1.0.0",
130
- "@azure/test-utils-perf": "^1.0.0",
131
- "@microsoft/api-extractor": "^7.18.11",
125
+ "@azure/identity": "2.0.0-beta.4",
126
+ "@azure/test-utils-perfstress": "^1.0.0",
127
+ "@microsoft/api-extractor": "7.7.11",
132
128
  "@rollup/plugin-commonjs": "11.0.2",
133
129
  "@rollup/plugin-inject": "^4.0.0",
134
130
  "@rollup/plugin-json": "^4.0.0",
@@ -174,14 +170,14 @@
174
170
  "moment": "^2.24.0",
175
171
  "nyc": "^14.0.0",
176
172
  "prettier": "^1.16.4",
177
- "puppeteer": "^10.2.0",
173
+ "puppeteer": "^3.3.0",
178
174
  "rimraf": "^3.0.0",
179
175
  "rollup": "^1.16.3",
180
176
  "rollup-plugin-shim": "^1.0.0",
181
177
  "rollup-plugin-sourcemaps": "^0.4.2",
182
178
  "rollup-plugin-terser": "^5.1.1",
183
179
  "sinon": "^9.0.2",
184
- "ts-node": "^10.0.0",
180
+ "ts-node": "^9.0.0",
185
181
  "typescript": "~4.2.0",
186
182
  "ws": "^7.1.1",
187
183
  "typedoc": "0.15.2"