@uoa/lambda-tracing 1.0.0-beta.2 → 1.0.0-beta.3

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/dist/tracing.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export declare function initializeTracing(): void;
1
2
  export declare function getRequestId(): string;
package/dist/tracing.js CHANGED
@@ -1,32 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRequestId = void 0;
3
+ exports.getRequestId = exports.initializeTracing = void 0;
4
4
  const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
5
5
  const instrumentation_aws_lambda_1 = require("@opentelemetry/instrumentation-aws-lambda");
6
6
  const instrumentation_1 = require("@opentelemetry/instrumentation");
7
7
  const UoaB3Propagator_1 = require("./UoaB3Propagator");
8
8
  const provider = new sdk_trace_node_1.NodeTracerProvider();
9
- provider.register({
10
- propagator: new UoaB3Propagator_1.UoaB3Propagator()
11
- });
12
9
  let requestId;
13
- (0, instrumentation_1.registerInstrumentations)({
14
- instrumentations: [
15
- new instrumentation_aws_lambda_1.AwsLambdaInstrumentation({
16
- requestHook: (span, { event, context }) => {
17
- span.setAttribute('faas.name', context.functionName);
18
- requestId = context.awsRequestId;
19
- },
20
- responseHook: (span, { err, res }) => {
21
- if (err instanceof Error)
22
- span.setAttribute('faas.error', err.message);
23
- if (res)
24
- span.setAttribute('faas.res', res);
25
- },
26
- disableAwsContextPropagation: true
27
- })
28
- ],
29
- });
10
+ function initializeTracing() {
11
+ provider.register({
12
+ propagator: new UoaB3Propagator_1.UoaB3Propagator()
13
+ });
14
+ (0, instrumentation_1.registerInstrumentations)({
15
+ instrumentations: [
16
+ new instrumentation_aws_lambda_1.AwsLambdaInstrumentation({
17
+ requestHook: (span, { event, context }) => {
18
+ span.setAttribute('faas.name', context.functionName);
19
+ requestId = context.awsRequestId;
20
+ },
21
+ responseHook: (span, { err, res }) => {
22
+ if (err instanceof Error)
23
+ span.setAttribute('faas.error', err.message);
24
+ if (res)
25
+ span.setAttribute('faas.res', res);
26
+ },
27
+ disableAwsContextPropagation: true
28
+ })
29
+ ]
30
+ });
31
+ }
32
+ exports.initializeTracing = initializeTracing;
30
33
  function getRequestId() {
31
34
  return requestId;
32
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uoa/lambda-tracing",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "Library for logging & distributed tracing in UoA Lambda projects",
5
5
  "repository": {
6
6
  "type": "git",
package/tracing.ts CHANGED
@@ -4,26 +4,30 @@ import {registerInstrumentations} from '@opentelemetry/instrumentation';
4
4
  import {UoaB3Propagator} from "./UoaB3Propagator";
5
5
 
6
6
  const provider = new NodeTracerProvider();
7
- provider.register({
8
- propagator: new UoaB3Propagator()
9
- });
10
7
  let requestId: string;
11
8
 
12
- registerInstrumentations({
13
- instrumentations: [
14
- new AwsLambdaInstrumentation({
15
- requestHook: (span, { event, context }) => {
16
- span.setAttribute('faas.name', context.functionName);
17
- requestId = context.awsRequestId;
18
- },
19
- responseHook: (span, { err, res }) => {
20
- if (err instanceof Error) span.setAttribute('faas.error', err.message);
21
- if (res) span.setAttribute('faas.res', res);
22
- },
23
- disableAwsContextPropagation: true
24
- })
25
- ],
26
- });
9
+ export function initializeTracing() {
10
+ provider.register({
11
+ propagator: new UoaB3Propagator()
12
+ });
13
+
14
+ registerInstrumentations({
15
+ instrumentations: [
16
+ new AwsLambdaInstrumentation({
17
+ requestHook: (span, { event, context }) => {
18
+ span.setAttribute('faas.name', context.functionName);
19
+ requestId = context.awsRequestId;
20
+ },
21
+ responseHook: (span, { err, res }) => {
22
+ if (err instanceof Error) span.setAttribute('faas.error', err.message);
23
+ if (res) span.setAttribute('faas.res', res);
24
+ },
25
+ disableAwsContextPropagation: true
26
+ })
27
+ ]
28
+ })
29
+
30
+ }
27
31
 
28
32
  export function getRequestId() {
29
33
  return requestId;