@opentelemetry/instrumentation-kafkajs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +76 -0
- package/build/src/index.d.ts +3 -0
- package/build/src/index.js +30 -0
- package/build/src/index.js.map +1 -0
- package/build/src/instrumentation.d.ts +19 -0
- package/build/src/instrumentation.js +226 -0
- package/build/src/instrumentation.js.map +1 -0
- package/build/src/propagator.d.ts +3 -0
- package/build/src/propagator.js +27 -0
- package/build/src/propagator.js.map +1 -0
- package/build/src/types.d.ts +27 -0
- package/build/src/types.js +3 -0
- package/build/src/types.js.map +1 -0
- package/build/src/version.d.ts +2 -0
- package/build/src/version.js +21 -0
- package/build/src/version.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# OpenTelemetry `kafkajs` Instrumentation for Node.js
|
|
2
|
+
|
|
3
|
+
[![NPM Published Version][npm-img]][npm-url]
|
|
4
|
+
[![Apache License][license-image]][license-image]
|
|
5
|
+
|
|
6
|
+
This module provides automatic instrumentation for the [`kafkajs`](https://www.npmjs.com/package/kafkajs) package, which may be loaded using the [`@opentelemetry/sdk-trace-node`](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-node) package and is included in the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle.
|
|
7
|
+
|
|
8
|
+
If total installation size is not constrained, it is recommended to use the [`@opentelemetry/auto-instrumentations-node`](https://www.npmjs.com/package/@opentelemetry/auto-instrumentations-node) bundle with [@opentelemetry/sdk-node](`https://www.npmjs.com/package/@opentelemetry/sdk-node`) for the most seamless instrumentation experience.
|
|
9
|
+
|
|
10
|
+
Compatible with OpenTelemetry JS API and SDK `1.0+`.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install --save @opentelemetry/instrumentation-kafkajs
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Supported versions
|
|
19
|
+
|
|
20
|
+
- `<3.0.0`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
|
|
26
|
+
const { KafkaJsInstrumentation } = require('@opentelemetry/instrumentation-kafkajs');
|
|
27
|
+
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
|
|
28
|
+
|
|
29
|
+
const provider = new NodeTracerProvider();
|
|
30
|
+
provider.register();
|
|
31
|
+
|
|
32
|
+
registerInstrumentations({
|
|
33
|
+
instrumentations: [
|
|
34
|
+
new KafkaJsInstrumentation({
|
|
35
|
+
// see below for available configuration
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Instrumentation Options
|
|
42
|
+
|
|
43
|
+
You can set the following:
|
|
44
|
+
|
|
45
|
+
| Options | Type | Description |
|
|
46
|
+
| ---------------------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
47
|
+
| `producerHook` | `KafkaProducerCustomAttributeFunction` | Function called before a producer message is sent. Allows for adding custom attributes to the span. |
|
|
48
|
+
| `consumerHook` | `KafkaConsumerCustomAttributeFunction` | Function called before a consumer message is processed. Allows for adding custom attributes to the span. |
|
|
49
|
+
|
|
50
|
+
## Semantic Conventions
|
|
51
|
+
|
|
52
|
+
This package uses `@opentelemetry/semantic-conventions` version `1.24+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
|
|
53
|
+
|
|
54
|
+
Attributes collected:
|
|
55
|
+
|
|
56
|
+
| Attribute | Short Description |
|
|
57
|
+
| -----------------------------| ----------------------------------------------------- |
|
|
58
|
+
| `messaging.system` | An identifier for the messaging system being used. |
|
|
59
|
+
| `messaging.destination` | The message destination name. |
|
|
60
|
+
| `messaging.operation` | A string identifying the kind of messaging operation. |
|
|
61
|
+
|
|
62
|
+
## Useful links
|
|
63
|
+
|
|
64
|
+
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
|
|
65
|
+
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
|
|
66
|
+
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
Apache 2.0 - See [LICENSE][license-url] for more information.
|
|
71
|
+
|
|
72
|
+
[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
|
|
73
|
+
[license-url]: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/LICENSE
|
|
74
|
+
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
|
|
75
|
+
[npm-url]: https://www.npmjs.com/package/@opentelemetry/instrumentation-kafkajs
|
|
76
|
+
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Finstrumentation-kafkajs.svg
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors, Aspecto
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
__exportStar(require("./instrumentation"), exports);
|
|
29
|
+
__exportStar(require("./types"), exports);
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,oDAAkC;AAClC,0CAAwB","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './instrumentation';\nexport * from './types';\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as kafkaJs from 'kafkajs';
|
|
2
|
+
import { KafkaJsInstrumentationConfig } from './types';
|
|
3
|
+
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
|
|
4
|
+
export declare class KafkaJsInstrumentation extends InstrumentationBase {
|
|
5
|
+
protected _config: KafkaJsInstrumentationConfig;
|
|
6
|
+
constructor(config?: KafkaJsInstrumentationConfig);
|
|
7
|
+
protected init(): InstrumentationNodeModuleDefinition<typeof kafkaJs>;
|
|
8
|
+
private _getConsumerPatch;
|
|
9
|
+
private _getProducerPatch;
|
|
10
|
+
private _getConsumerRunPatch;
|
|
11
|
+
private _getConsumerEachMessagePatch;
|
|
12
|
+
private _getConsumerEachBatchPatch;
|
|
13
|
+
private _getProducerSendBatchPatch;
|
|
14
|
+
private _getProducerSendPatch;
|
|
15
|
+
private _endSpansOnPromise;
|
|
16
|
+
private _startConsumerSpan;
|
|
17
|
+
private _startProducerSpan;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors, Aspecto
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.KafkaJsInstrumentation = void 0;
|
|
19
|
+
const api_1 = require("@opentelemetry/api");
|
|
20
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
21
|
+
const version_1 = require("./version");
|
|
22
|
+
const propagator_1 = require("./propagator");
|
|
23
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
24
|
+
class KafkaJsInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
25
|
+
constructor(config = {}) {
|
|
26
|
+
super('@opentelemetry/instrumentation-kafkajs', version_1.VERSION, config);
|
|
27
|
+
}
|
|
28
|
+
init() {
|
|
29
|
+
const unpatch = (moduleExports) => {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
if ((0, instrumentation_1.isWrapped)((_a = moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.Kafka) === null || _a === void 0 ? void 0 : _a.prototype.producer)) {
|
|
32
|
+
this._unwrap(moduleExports.Kafka.prototype, 'producer');
|
|
33
|
+
}
|
|
34
|
+
if ((0, instrumentation_1.isWrapped)((_b = moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.Kafka) === null || _b === void 0 ? void 0 : _b.prototype.consumer)) {
|
|
35
|
+
this._unwrap(moduleExports.Kafka.prototype, 'consumer');
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const module = new instrumentation_1.InstrumentationNodeModuleDefinition('kafkajs', ['< 3'], (moduleExports) => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
unpatch(moduleExports);
|
|
41
|
+
this._wrap((_a = moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.Kafka) === null || _a === void 0 ? void 0 : _a.prototype, 'producer', this._getProducerPatch());
|
|
42
|
+
this._wrap((_b = moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.Kafka) === null || _b === void 0 ? void 0 : _b.prototype, 'consumer', this._getConsumerPatch());
|
|
43
|
+
return moduleExports;
|
|
44
|
+
}, unpatch);
|
|
45
|
+
return module;
|
|
46
|
+
}
|
|
47
|
+
_getConsumerPatch() {
|
|
48
|
+
const instrumentation = this;
|
|
49
|
+
return (original) => {
|
|
50
|
+
return function consumer(...args) {
|
|
51
|
+
const newConsumer = original.apply(this, args);
|
|
52
|
+
if ((0, instrumentation_1.isWrapped)(newConsumer.run)) {
|
|
53
|
+
instrumentation._unwrap(newConsumer, 'run');
|
|
54
|
+
}
|
|
55
|
+
instrumentation._wrap(newConsumer, 'run', instrumentation._getConsumerRunPatch());
|
|
56
|
+
return newConsumer;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
_getProducerPatch() {
|
|
61
|
+
const instrumentation = this;
|
|
62
|
+
return (original) => {
|
|
63
|
+
return function consumer(...args) {
|
|
64
|
+
const newProducer = original.apply(this, args);
|
|
65
|
+
if ((0, instrumentation_1.isWrapped)(newProducer.sendBatch)) {
|
|
66
|
+
instrumentation._unwrap(newProducer, 'sendBatch');
|
|
67
|
+
}
|
|
68
|
+
instrumentation._wrap(newProducer, 'sendBatch', instrumentation._getProducerSendBatchPatch());
|
|
69
|
+
if ((0, instrumentation_1.isWrapped)(newProducer.send)) {
|
|
70
|
+
instrumentation._unwrap(newProducer, 'send');
|
|
71
|
+
}
|
|
72
|
+
instrumentation._wrap(newProducer, 'send', instrumentation._getProducerSendPatch());
|
|
73
|
+
return newProducer;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
_getConsumerRunPatch() {
|
|
78
|
+
const instrumentation = this;
|
|
79
|
+
return (original) => {
|
|
80
|
+
return function run(...args) {
|
|
81
|
+
const config = args[0];
|
|
82
|
+
if (config === null || config === void 0 ? void 0 : config.eachMessage) {
|
|
83
|
+
if ((0, instrumentation_1.isWrapped)(config.eachMessage)) {
|
|
84
|
+
instrumentation._unwrap(config, 'eachMessage');
|
|
85
|
+
}
|
|
86
|
+
instrumentation._wrap(config, 'eachMessage', instrumentation._getConsumerEachMessagePatch());
|
|
87
|
+
}
|
|
88
|
+
if (config === null || config === void 0 ? void 0 : config.eachBatch) {
|
|
89
|
+
if ((0, instrumentation_1.isWrapped)(config.eachBatch)) {
|
|
90
|
+
instrumentation._unwrap(config, 'eachBatch');
|
|
91
|
+
}
|
|
92
|
+
instrumentation._wrap(config, 'eachBatch', instrumentation._getConsumerEachBatchPatch());
|
|
93
|
+
}
|
|
94
|
+
return original.call(this, config);
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
_getConsumerEachMessagePatch() {
|
|
99
|
+
const instrumentation = this;
|
|
100
|
+
return (original) => {
|
|
101
|
+
return function eachMessage(...args) {
|
|
102
|
+
const payload = args[0];
|
|
103
|
+
const propagatedContext = api_1.propagation.extract(api_1.ROOT_CONTEXT, payload.message.headers, propagator_1.bufferTextMapGetter);
|
|
104
|
+
const span = instrumentation._startConsumerSpan(payload.topic, payload.message, semantic_conventions_1.MESSAGINGOPERATIONVALUES_PROCESS, propagatedContext);
|
|
105
|
+
const eachMessagePromise = api_1.context.with(api_1.trace.setSpan(propagatedContext, span), () => {
|
|
106
|
+
return original.apply(this, args);
|
|
107
|
+
});
|
|
108
|
+
return instrumentation._endSpansOnPromise([span], eachMessagePromise);
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
_getConsumerEachBatchPatch() {
|
|
113
|
+
return (original) => {
|
|
114
|
+
const instrumentation = this;
|
|
115
|
+
return function eachBatch(...args) {
|
|
116
|
+
const payload = args[0];
|
|
117
|
+
// https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#topic-with-multiple-consumers
|
|
118
|
+
const receivingSpan = instrumentation._startConsumerSpan(payload.batch.topic, undefined, semantic_conventions_1.MESSAGINGOPERATIONVALUES_RECEIVE, api_1.ROOT_CONTEXT);
|
|
119
|
+
return api_1.context.with(api_1.trace.setSpan(api_1.context.active(), receivingSpan), () => {
|
|
120
|
+
const spans = payload.batch.messages.map((message) => {
|
|
121
|
+
var _a;
|
|
122
|
+
const propagatedContext = api_1.propagation.extract(api_1.ROOT_CONTEXT, message.headers, propagator_1.bufferTextMapGetter);
|
|
123
|
+
const spanContext = (_a = api_1.trace
|
|
124
|
+
.getSpan(propagatedContext)) === null || _a === void 0 ? void 0 : _a.spanContext();
|
|
125
|
+
let origSpanLink;
|
|
126
|
+
if (spanContext) {
|
|
127
|
+
origSpanLink = {
|
|
128
|
+
context: spanContext,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return instrumentation._startConsumerSpan(payload.batch.topic, message, semantic_conventions_1.MESSAGINGOPERATIONVALUES_PROCESS, undefined, origSpanLink);
|
|
132
|
+
});
|
|
133
|
+
const batchMessagePromise = original.apply(this, args);
|
|
134
|
+
spans.unshift(receivingSpan);
|
|
135
|
+
return instrumentation._endSpansOnPromise(spans, batchMessagePromise);
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
_getProducerSendBatchPatch() {
|
|
141
|
+
const instrumentation = this;
|
|
142
|
+
return (original) => {
|
|
143
|
+
return function sendBatch(...args) {
|
|
144
|
+
const batch = args[0];
|
|
145
|
+
const messages = batch.topicMessages || [];
|
|
146
|
+
const spans = messages
|
|
147
|
+
.map(topicMessage => topicMessage.messages.map(message => instrumentation._startProducerSpan(topicMessage.topic, message)))
|
|
148
|
+
.reduce((acc, val) => acc.concat(val), []);
|
|
149
|
+
const origSendResult = original.apply(this, args);
|
|
150
|
+
return instrumentation._endSpansOnPromise(spans, origSendResult);
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
_getProducerSendPatch() {
|
|
155
|
+
const instrumentation = this;
|
|
156
|
+
return (original) => {
|
|
157
|
+
return function send(...args) {
|
|
158
|
+
const record = args[0];
|
|
159
|
+
const spans = record.messages.map(message => {
|
|
160
|
+
return instrumentation._startProducerSpan(record.topic, message);
|
|
161
|
+
});
|
|
162
|
+
const origSendResult = original.apply(this, args);
|
|
163
|
+
return instrumentation._endSpansOnPromise(spans, origSendResult);
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
_endSpansOnPromise(spans, sendPromise) {
|
|
168
|
+
return Promise.resolve(sendPromise)
|
|
169
|
+
.catch(reason => {
|
|
170
|
+
let errorMessage;
|
|
171
|
+
if (typeof reason === 'string')
|
|
172
|
+
errorMessage = reason;
|
|
173
|
+
else if (typeof reason === 'object' &&
|
|
174
|
+
Object.prototype.hasOwnProperty.call(reason, 'message'))
|
|
175
|
+
errorMessage = reason.message;
|
|
176
|
+
spans.forEach(span => span.setStatus({
|
|
177
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
178
|
+
message: errorMessage,
|
|
179
|
+
}));
|
|
180
|
+
throw reason;
|
|
181
|
+
})
|
|
182
|
+
.finally(() => {
|
|
183
|
+
spans.forEach(span => span.end());
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
_startConsumerSpan(topic, message, operation, context, link) {
|
|
187
|
+
var _a;
|
|
188
|
+
const span = this.tracer.startSpan(topic, {
|
|
189
|
+
kind: api_1.SpanKind.CONSUMER,
|
|
190
|
+
attributes: {
|
|
191
|
+
[semantic_conventions_1.SEMATTRS_MESSAGING_SYSTEM]: 'kafka',
|
|
192
|
+
[semantic_conventions_1.SEMATTRS_MESSAGING_DESTINATION]: topic,
|
|
193
|
+
[semantic_conventions_1.SEMATTRS_MESSAGING_OPERATION]: operation,
|
|
194
|
+
},
|
|
195
|
+
links: link ? [link] : [],
|
|
196
|
+
}, context);
|
|
197
|
+
if (((_a = this._config) === null || _a === void 0 ? void 0 : _a.consumerHook) && message) {
|
|
198
|
+
(0, instrumentation_1.safeExecuteInTheMiddle)(() => this._config.consumerHook(span, { topic, message }), e => {
|
|
199
|
+
if (e)
|
|
200
|
+
this._diag.error('consumerHook error', e);
|
|
201
|
+
}, true);
|
|
202
|
+
}
|
|
203
|
+
return span;
|
|
204
|
+
}
|
|
205
|
+
_startProducerSpan(topic, message) {
|
|
206
|
+
var _a, _b;
|
|
207
|
+
const span = this.tracer.startSpan(topic, {
|
|
208
|
+
kind: api_1.SpanKind.PRODUCER,
|
|
209
|
+
attributes: {
|
|
210
|
+
[semantic_conventions_1.SEMATTRS_MESSAGING_SYSTEM]: 'kafka',
|
|
211
|
+
[semantic_conventions_1.SEMATTRS_MESSAGING_DESTINATION]: topic,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
message.headers = (_a = message.headers) !== null && _a !== void 0 ? _a : {};
|
|
215
|
+
api_1.propagation.inject(api_1.trace.setSpan(api_1.context.active(), span), message.headers);
|
|
216
|
+
if ((_b = this._config) === null || _b === void 0 ? void 0 : _b.producerHook) {
|
|
217
|
+
(0, instrumentation_1.safeExecuteInTheMiddle)(() => this._config.producerHook(span, { topic, message }), e => {
|
|
218
|
+
if (e)
|
|
219
|
+
this._diag.error('producerHook error', e);
|
|
220
|
+
}, true);
|
|
221
|
+
}
|
|
222
|
+
return span;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.KafkaJsInstrumentation = KafkaJsInstrumentation;
|
|
226
|
+
//# sourceMappingURL=instrumentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../src/instrumentation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAU4B;AAC5B,8EAM6C;AAa7C,uCAAoC;AACpC,6CAAmD;AACnD,oEAKwC;AAExC,MAAa,sBAAuB,SAAQ,qCAAmB;IAG7D,YAAY,SAAuC,EAAE;QACnD,KAAK,CAAC,wCAAwC,EAAE,iBAAO,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IAES,IAAI;QACZ,MAAM,OAAO,GAAG,CAAC,aAA6B,EAAE,EAAE;;YAChD,IAAI,IAAA,2BAAS,EAAC,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CA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GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAa,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAC1D,CAAC,CAAC,EAAE;gBACF,IAAI,CAAC;oBAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC;YACnD,CAAC,EACD,IAAI,CACL,CAAC;SACH;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA/VD,wDA+VC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n SpanKind,\n Span,\n SpanStatusCode,\n Context,\n propagation,\n Link,\n trace,\n context,\n ROOT_CONTEXT,\n} from '@opentelemetry/api';\nimport {\n MESSAGINGOPERATIONVALUES_PROCESS,\n MESSAGINGOPERATIONVALUES_RECEIVE,\n SEMATTRS_MESSAGING_SYSTEM,\n SEMATTRS_MESSAGING_DESTINATION,\n SEMATTRS_MESSAGING_OPERATION,\n} from '@opentelemetry/semantic-conventions';\nimport type * as kafkaJs from 'kafkajs';\nimport type {\n EachBatchHandler,\n EachMessageHandler,\n Producer,\n RecordMetadata,\n Message,\n ConsumerRunConfig,\n KafkaMessage,\n Consumer,\n} from 'kafkajs';\nimport { KafkaJsInstrumentationConfig } from './types';\nimport { VERSION } from './version';\nimport { bufferTextMapGetter } from './propagator';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n safeExecuteInTheMiddle,\n isWrapped,\n} from '@opentelemetry/instrumentation';\n\nexport class KafkaJsInstrumentation extends InstrumentationBase {\n protected override _config!: KafkaJsInstrumentationConfig;\n\n constructor(config: KafkaJsInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-kafkajs', VERSION, config);\n }\n\n protected init() {\n const unpatch = (moduleExports: typeof kafkaJs) => {\n if (isWrapped(moduleExports?.Kafka?.prototype.producer)) {\n this._unwrap(moduleExports.Kafka.prototype, 'producer');\n }\n if (isWrapped(moduleExports?.Kafka?.prototype.consumer)) {\n this._unwrap(moduleExports.Kafka.prototype, 'consumer');\n }\n };\n\n const module = new InstrumentationNodeModuleDefinition(\n 'kafkajs',\n ['< 3'],\n (moduleExports: typeof kafkaJs) => {\n unpatch(moduleExports);\n this._wrap(\n moduleExports?.Kafka?.prototype,\n 'producer',\n this._getProducerPatch()\n );\n this._wrap(\n moduleExports?.Kafka?.prototype,\n 'consumer',\n this._getConsumerPatch()\n );\n\n return moduleExports;\n },\n unpatch\n );\n return module;\n }\n\n private _getConsumerPatch() {\n const instrumentation = this;\n return (original: kafkaJs.Kafka['consumer']) => {\n return function consumer(\n this: kafkaJs.Kafka,\n ...args: Parameters<kafkaJs.Kafka['consumer']>\n ) {\n const newConsumer: Consumer = original.apply(this, args);\n\n if (isWrapped(newConsumer.run)) {\n instrumentation._unwrap(newConsumer, 'run');\n }\n\n instrumentation._wrap(\n newConsumer,\n 'run',\n instrumentation._getConsumerRunPatch()\n );\n\n return newConsumer;\n };\n };\n }\n\n private _getProducerPatch() {\n const instrumentation = this;\n return (original: kafkaJs.Kafka['producer']) => {\n return function consumer(\n this: kafkaJs.Kafka,\n ...args: Parameters<kafkaJs.Kafka['producer']>\n ) {\n const newProducer: Producer = original.apply(this, args);\n\n if (isWrapped(newProducer.sendBatch)) {\n instrumentation._unwrap(newProducer, 'sendBatch');\n }\n instrumentation._wrap(\n newProducer,\n 'sendBatch',\n instrumentation._getProducerSendBatchPatch()\n );\n\n if (isWrapped(newProducer.send)) {\n instrumentation._unwrap(newProducer, 'send');\n }\n instrumentation._wrap(\n newProducer,\n 'send',\n instrumentation._getProducerSendPatch()\n );\n\n return newProducer;\n };\n };\n }\n\n private _getConsumerRunPatch() {\n const instrumentation = this;\n return (original: Consumer['run']) => {\n return function run(\n this: Consumer,\n ...args: Parameters<Consumer['run']>\n ): ReturnType<Consumer['run']> {\n const config = args[0];\n if (config?.eachMessage) {\n if (isWrapped(config.eachMessage)) {\n instrumentation._unwrap(config, 'eachMessage');\n }\n instrumentation._wrap(\n config,\n 'eachMessage',\n instrumentation._getConsumerEachMessagePatch()\n );\n }\n if (config?.eachBatch) {\n if (isWrapped(config.eachBatch)) {\n instrumentation._unwrap(config, 'eachBatch');\n }\n instrumentation._wrap(\n config,\n 'eachBatch',\n instrumentation._getConsumerEachBatchPatch()\n );\n }\n return original.call(this, config);\n };\n };\n }\n\n private _getConsumerEachMessagePatch() {\n const instrumentation = this;\n return (original: ConsumerRunConfig['eachMessage']) => {\n return function eachMessage(\n this: unknown,\n ...args: Parameters<EachMessageHandler>\n ): Promise<void> {\n const payload = args[0];\n const propagatedContext: Context = propagation.extract(\n ROOT_CONTEXT,\n payload.message.headers,\n bufferTextMapGetter\n );\n const span = instrumentation._startConsumerSpan(\n payload.topic,\n payload.message,\n MESSAGINGOPERATIONVALUES_PROCESS,\n propagatedContext\n );\n\n const eachMessagePromise = context.with(\n trace.setSpan(propagatedContext, span),\n () => {\n return original!.apply(this, args);\n }\n );\n return instrumentation._endSpansOnPromise([span], eachMessagePromise);\n };\n };\n }\n\n private _getConsumerEachBatchPatch() {\n return (original: ConsumerRunConfig['eachBatch']) => {\n const instrumentation = this;\n return function eachBatch(\n this: unknown,\n ...args: Parameters<EachBatchHandler>\n ): Promise<void> {\n const payload = args[0];\n // https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#topic-with-multiple-consumers\n const receivingSpan = instrumentation._startConsumerSpan(\n payload.batch.topic,\n undefined,\n MESSAGINGOPERATIONVALUES_RECEIVE,\n ROOT_CONTEXT\n );\n return context.with(\n trace.setSpan(context.active(), receivingSpan),\n () => {\n const spans = payload.batch.messages.map(\n (message: KafkaMessage) => {\n const propagatedContext: Context = propagation.extract(\n ROOT_CONTEXT,\n message.headers,\n bufferTextMapGetter\n );\n const spanContext = trace\n .getSpan(propagatedContext)\n ?.spanContext();\n let origSpanLink: Link | undefined;\n if (spanContext) {\n origSpanLink = {\n context: spanContext,\n };\n }\n return instrumentation._startConsumerSpan(\n payload.batch.topic,\n message,\n MESSAGINGOPERATIONVALUES_PROCESS,\n undefined,\n origSpanLink\n );\n }\n );\n const batchMessagePromise: Promise<void> = original!.apply(\n this,\n args\n );\n spans.unshift(receivingSpan);\n return instrumentation._endSpansOnPromise(\n spans,\n batchMessagePromise\n );\n }\n );\n };\n };\n }\n\n private _getProducerSendBatchPatch() {\n const instrumentation = this;\n return (original: Producer['sendBatch']) => {\n return function sendBatch(\n this: Producer,\n ...args: Parameters<Producer['sendBatch']>\n ): ReturnType<Producer['sendBatch']> {\n const batch = args[0];\n const messages = batch.topicMessages || [];\n const spans: Span[] = messages\n .map(topicMessage =>\n topicMessage.messages.map(message =>\n instrumentation._startProducerSpan(topicMessage.topic, message)\n )\n )\n .reduce((acc, val) => acc.concat(val), []);\n\n const origSendResult: Promise<RecordMetadata[]> = original.apply(\n this,\n args\n );\n return instrumentation._endSpansOnPromise(spans, origSendResult);\n };\n };\n }\n\n private _getProducerSendPatch() {\n const instrumentation = this;\n return (original: Producer['send']) => {\n return function send(\n this: Producer,\n ...args: Parameters<Producer['send']>\n ): ReturnType<Producer['send']> {\n const record = args[0];\n const spans: Span[] = record.messages.map(message => {\n return instrumentation._startProducerSpan(record.topic, message);\n });\n\n const origSendResult: Promise<RecordMetadata[]> = original.apply(\n this,\n args\n );\n return instrumentation._endSpansOnPromise(spans, origSendResult);\n };\n };\n }\n\n private _endSpansOnPromise<T>(\n spans: Span[],\n sendPromise: Promise<T>\n ): Promise<T> {\n return Promise.resolve(sendPromise)\n .catch(reason => {\n let errorMessage: string;\n if (typeof reason === 'string') errorMessage = reason;\n else if (\n typeof reason === 'object' &&\n Object.prototype.hasOwnProperty.call(reason, 'message')\n )\n errorMessage = reason.message;\n\n spans.forEach(span =>\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: errorMessage,\n })\n );\n\n throw reason;\n })\n .finally(() => {\n spans.forEach(span => span.end());\n });\n }\n\n private _startConsumerSpan(\n topic: string,\n message: KafkaMessage | undefined,\n operation: string,\n context: Context | undefined,\n link?: Link\n ) {\n const span = this.tracer.startSpan(\n topic,\n {\n kind: SpanKind.CONSUMER,\n attributes: {\n [SEMATTRS_MESSAGING_SYSTEM]: 'kafka',\n [SEMATTRS_MESSAGING_DESTINATION]: topic,\n [SEMATTRS_MESSAGING_OPERATION]: operation,\n },\n links: link ? [link] : [],\n },\n context\n );\n\n if (this._config?.consumerHook && message) {\n safeExecuteInTheMiddle(\n () => this._config.consumerHook!(span, { topic, message }),\n e => {\n if (e) this._diag.error('consumerHook error', e);\n },\n true\n );\n }\n\n return span;\n }\n\n private _startProducerSpan(topic: string, message: Message) {\n const span = this.tracer.startSpan(topic, {\n kind: SpanKind.PRODUCER,\n attributes: {\n [SEMATTRS_MESSAGING_SYSTEM]: 'kafka',\n [SEMATTRS_MESSAGING_DESTINATION]: topic,\n },\n });\n\n message.headers = message.headers ?? {};\n propagation.inject(trace.setSpan(context.active(), span), message.headers);\n\n if (this._config?.producerHook) {\n safeExecuteInTheMiddle(\n () => this._config.producerHook!(span, { topic, message }),\n e => {\n if (e) this._diag.error('producerHook error', e);\n },\n true\n );\n }\n\n return span;\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bufferTextMapGetter = void 0;
|
|
4
|
+
/*
|
|
5
|
+
same as open telemetry's `defaultTextMapGetter`,
|
|
6
|
+
but also handle case where header is buffer,
|
|
7
|
+
adding toString() to make sure string is returned
|
|
8
|
+
*/
|
|
9
|
+
exports.bufferTextMapGetter = {
|
|
10
|
+
get(carrier, key) {
|
|
11
|
+
var _a;
|
|
12
|
+
if (!carrier) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const keys = Object.keys(carrier);
|
|
16
|
+
for (const carrierKey of keys) {
|
|
17
|
+
if (carrierKey === key || carrierKey.toLowerCase() === key) {
|
|
18
|
+
return (_a = carrier[carrierKey]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
},
|
|
23
|
+
keys(carrier) {
|
|
24
|
+
return carrier ? Object.keys(carrier) : [];
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=propagator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propagator.js","sourceRoot":"","sources":["../../src/propagator.ts"],"names":[],"mappings":";;;AAiBA;;;;EAIE;AACW,QAAA,mBAAmB,GAAkB;IAChD,GAAG,CAAC,OAAO,EAAE,GAAG;;QACd,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAElC,KAAK,MAAM,UAAU,IAAI,IAAI,EAAE;YAC7B,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,CAAC,WAAW,EAAE,KAAK,GAAG,EAAE;gBAC1D,OAAO,MAAA,OAAO,CAAC,UAAU,CAAC,0CAAE,QAAQ,EAAE,CAAC;aACxC;SACF;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,OAAO;QACV,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7C,CAAC;CACF,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { TextMapGetter } from '@opentelemetry/api';\n\n/*\nsame as open telemetry's `defaultTextMapGetter`,\nbut also handle case where header is buffer,\nadding toString() to make sure string is returned\n*/\nexport const bufferTextMapGetter: TextMapGetter = {\n get(carrier, key) {\n if (!carrier) {\n return undefined;\n }\n\n const keys = Object.keys(carrier);\n\n for (const carrierKey of keys) {\n if (carrierKey === key || carrierKey.toLowerCase() === key) {\n return carrier[carrierKey]?.toString();\n }\n }\n\n return undefined;\n },\n\n keys(carrier) {\n return carrier ? Object.keys(carrier) : [];\n },\n};\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Span } from '@opentelemetry/api';
|
|
3
|
+
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
|
|
4
|
+
export interface KafkajsMessage {
|
|
5
|
+
key?: Buffer | string | null;
|
|
6
|
+
value: Buffer | string | null;
|
|
7
|
+
partition?: number;
|
|
8
|
+
headers?: Record<string, Buffer | string | (Buffer | string)[] | undefined>;
|
|
9
|
+
timestamp?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MessageInfo<T = KafkajsMessage> {
|
|
12
|
+
topic: string;
|
|
13
|
+
message: T;
|
|
14
|
+
}
|
|
15
|
+
export interface KafkaProducerCustomAttributeFunction<T = KafkajsMessage> {
|
|
16
|
+
(span: Span, info: MessageInfo<T>): void;
|
|
17
|
+
}
|
|
18
|
+
export interface KafkaConsumerCustomAttributeFunction<T = KafkajsMessage> {
|
|
19
|
+
(span: Span, info: MessageInfo<T>): void;
|
|
20
|
+
}
|
|
21
|
+
export interface KafkaJsInstrumentationConfig extends InstrumentationConfig {
|
|
22
|
+
/** hook for adding custom attributes before producer message is sent */
|
|
23
|
+
producerHook?: KafkaProducerCustomAttributeFunction;
|
|
24
|
+
/** hook for adding custom attributes before consumer message is processed */
|
|
25
|
+
consumerHook?: KafkaConsumerCustomAttributeFunction;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors, Aspecto\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Span } from '@opentelemetry/api';\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\n\nexport interface KafkajsMessage {\n key?: Buffer | string | null;\n value: Buffer | string | null;\n partition?: number;\n headers?: Record<string, Buffer | string | (Buffer | string)[] | undefined>;\n timestamp?: string;\n}\n\nexport interface MessageInfo<T = KafkajsMessage> {\n topic: string;\n message: T;\n}\n\nexport interface KafkaProducerCustomAttributeFunction<T = KafkajsMessage> {\n (span: Span, info: MessageInfo<T>): void;\n}\n\nexport interface KafkaConsumerCustomAttributeFunction<T = KafkajsMessage> {\n (span: Span, info: MessageInfo<T>): void;\n}\n\nexport interface KafkaJsInstrumentationConfig extends InstrumentationConfig {\n /** hook for adding custom attributes before producer message is sent */\n producerHook?: KafkaProducerCustomAttributeFunction;\n\n /** hook for adding custom attributes before consumer message is processed */\n consumerHook?: KafkaConsumerCustomAttributeFunction;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.VERSION = void 0;
|
|
19
|
+
// this is autogenerated file, see scripts/version-update.js
|
|
20
|
+
exports.VERSION = '0.0.1';
|
|
21
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.0.1';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opentelemetry/instrumentation-kafkajs",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "OpenTelemetry automatic instrumentation package for kafkajs",
|
|
5
|
+
"main": "build/src/index.js",
|
|
6
|
+
"types": "build/src/index.d.ts",
|
|
7
|
+
"repository": "open-telemetry/opentelemetry-js-contrib",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "ts-mocha --require @opentelemetry/contrib-test-utils -p tsconfig.json 'test/**/*.test.ts'",
|
|
10
|
+
"tdd": "npm run test -- --watch-extensions ts --watch",
|
|
11
|
+
"clean": "rimraf build/*",
|
|
12
|
+
"lint": "eslint . --ext .ts",
|
|
13
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
14
|
+
"precompile": "tsc --version && lerna run version:update --scope @opentelemetry/instrumentation-kafkajs --include-dependencies",
|
|
15
|
+
"prewatch": "npm run precompile",
|
|
16
|
+
"prepublishOnly": "npm run compile",
|
|
17
|
+
"version:update": "node ../../../scripts/version-update.js",
|
|
18
|
+
"compile": "tsc -p ."
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"kafkajs",
|
|
22
|
+
"instrumentation",
|
|
23
|
+
"nodejs",
|
|
24
|
+
"opentelemetry",
|
|
25
|
+
"profiling",
|
|
26
|
+
"tracing"
|
|
27
|
+
],
|
|
28
|
+
"author": "OpenTelemetry Authors",
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=14"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"build/src/**/*.js",
|
|
35
|
+
"build/src/**/*.js.map",
|
|
36
|
+
"build/src/**/*.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@opentelemetry/api": "^1.3.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@opentelemetry/api": "^1.3.0",
|
|
46
|
+
"@opentelemetry/contrib-test-utils": "^0.38.0",
|
|
47
|
+
"@opentelemetry/sdk-trace-base": "^1.24.0",
|
|
48
|
+
"@types/mocha": "7.0.2",
|
|
49
|
+
"@types/node": "18.6.5",
|
|
50
|
+
"@types/sinon": "^10.0.11",
|
|
51
|
+
"kafkajs": "^2.2.4",
|
|
52
|
+
"mocha": "7.2.0",
|
|
53
|
+
"nyc": "15.1.0",
|
|
54
|
+
"rimraf": "5.0.5",
|
|
55
|
+
"sinon": "15.2.0",
|
|
56
|
+
"ts-mocha": "10.0.0",
|
|
57
|
+
"typescript": "4.4.4"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@opentelemetry/instrumentation": "^0.51.0",
|
|
61
|
+
"@opentelemetry/semantic-conventions": "^1.24.0"
|
|
62
|
+
},
|
|
63
|
+
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-kafkajs#readme",
|
|
64
|
+
"gitHead": "b41797b2b8a11a7db4d3ec13c2452d824f45f82d"
|
|
65
|
+
}
|