@dagger.io/dagger 0.11.1 → 0.11.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.
Files changed (61) hide show
  1. package/dist/api/client.gen.d.ts +83 -2
  2. package/dist/api/client.gen.d.ts.map +1 -1
  3. package/dist/api/client.gen.js +197 -2
  4. package/dist/common/utils.d.ts +2 -1
  5. package/dist/common/utils.d.ts.map +1 -1
  6. package/dist/connect.d.ts.map +1 -1
  7. package/dist/connect.js +18 -2
  8. package/dist/context/context.d.ts +1 -0
  9. package/dist/context/context.d.ts.map +1 -1
  10. package/dist/context/context.js +6 -0
  11. package/dist/entrypoint/entrypoint.d.ts.map +1 -1
  12. package/dist/entrypoint/entrypoint.js +19 -9
  13. package/dist/entrypoint/load.d.ts +5 -5
  14. package/dist/entrypoint/load.d.ts.map +1 -1
  15. package/dist/entrypoint/load.js +12 -0
  16. package/dist/entrypoint/register.d.ts.map +1 -1
  17. package/dist/entrypoint/register.js +2 -0
  18. package/dist/graphql/client.d.ts.map +1 -1
  19. package/dist/graphql/client.js +8 -1
  20. package/dist/introspector/registry/registry.d.ts +2 -2
  21. package/dist/introspector/registry/registry.d.ts.map +1 -1
  22. package/dist/introspector/scanner/abtractions/argument.d.ts.map +1 -1
  23. package/dist/introspector/scanner/abtractions/argument.js +2 -4
  24. package/dist/introspector/scanner/abtractions/constructor.d.ts +1 -1
  25. package/dist/introspector/scanner/abtractions/constructor.d.ts.map +1 -1
  26. package/dist/introspector/scanner/abtractions/method.d.ts +1 -1
  27. package/dist/introspector/scanner/abtractions/method.d.ts.map +1 -1
  28. package/dist/introspector/scanner/abtractions/method.js +2 -3
  29. package/dist/introspector/scanner/abtractions/module.d.ts.map +1 -1
  30. package/dist/introspector/scanner/abtractions/module.js +1 -1
  31. package/dist/introspector/scanner/abtractions/object.d.ts +1 -1
  32. package/dist/introspector/scanner/abtractions/object.d.ts.map +1 -1
  33. package/dist/introspector/scanner/abtractions/object.js +2 -2
  34. package/dist/introspector/scanner/abtractions/property.d.ts +1 -1
  35. package/dist/introspector/scanner/abtractions/property.d.ts.map +1 -1
  36. package/dist/introspector/scanner/abtractions/property.js +2 -4
  37. package/dist/introspector/scanner/scan.d.ts +1 -1
  38. package/dist/introspector/scanner/scan.d.ts.map +1 -1
  39. package/dist/introspector/scanner/typeDefs.d.ts +11 -2
  40. package/dist/introspector/scanner/typeDefs.d.ts.map +1 -1
  41. package/dist/introspector/scanner/utils.d.ts +2 -2
  42. package/dist/introspector/scanner/utils.d.ts.map +1 -1
  43. package/dist/introspector/scanner/utils.js +13 -3
  44. package/dist/provisioning/default.d.ts +1 -1
  45. package/dist/provisioning/default.js +1 -1
  46. package/dist/telemetry/attributes.d.ts +13 -0
  47. package/dist/telemetry/attributes.d.ts.map +1 -0
  48. package/dist/telemetry/attributes.js +12 -0
  49. package/dist/telemetry/index.d.ts +3 -0
  50. package/dist/telemetry/index.d.ts.map +1 -0
  51. package/dist/telemetry/index.js +2 -0
  52. package/dist/telemetry/init.d.ts +21 -0
  53. package/dist/telemetry/init.d.ts.map +1 -0
  54. package/dist/telemetry/init.js +66 -0
  55. package/dist/telemetry/telemetry.d.ts +16 -0
  56. package/dist/telemetry/telemetry.d.ts.map +1 -0
  57. package/dist/telemetry/telemetry.js +38 -0
  58. package/dist/telemetry/tracer.d.ts +32 -0
  59. package/dist/telemetry/tracer.d.ts.map +1 -0
  60. package/dist/telemetry/tracer.js +54 -0
  61. package/package.json +21 -12
@@ -0,0 +1,66 @@
1
+ import { getEnvWithoutDefaults } from "@opentelemetry/core";
2
+ import { NodeSDK } from "@opentelemetry/sdk-node";
3
+ const SERVICE_NAME = "dagger-typescript-sdk";
4
+ const env = getEnvWithoutDefaults();
5
+ /*
6
+ * Look for variables prefixed with OTEL to see if OpenTelemetry is configured.
7
+ */
8
+ function otelConfigured() {
9
+ return Object.keys(process.env).some((key) => key.startsWith("OTEL_"));
10
+ }
11
+ /**
12
+ * A wrapper around the OpenTelemetry SDK to configure it for Dagger.
13
+ */
14
+ export class DaggerOtelConfigurator {
15
+ is_configured = false;
16
+ sdk;
17
+ /**
18
+ * Initialize the Open Telemetry SDK if enabled or not already configured.
19
+ */
20
+ initialize() {
21
+ if (this.is_configured) {
22
+ return;
23
+ }
24
+ this.configure();
25
+ this.is_configured = true;
26
+ }
27
+ configure() {
28
+ if (!otelConfigured()) {
29
+ return;
30
+ }
31
+ if (env.OTEL_SDK_DISABLED) {
32
+ return;
33
+ }
34
+ this.setupEnv();
35
+ // Create the node SDK with the context manager, the resource and the exporter.
36
+ this.sdk = new NodeSDK({
37
+ serviceName: SERVICE_NAME,
38
+ });
39
+ // Register the SDK to the OpenTelemetry API
40
+ this.sdk.start();
41
+ }
42
+ /**
43
+ * Shutdown the Open Telemetry SDK to flush traces and metrics and close the connection.
44
+ */
45
+ async close() {
46
+ if (this.sdk) {
47
+ this.sdk.shutdown();
48
+ }
49
+ }
50
+ /**
51
+ * Setup environment for auto-configuring the SDK.
52
+ */
53
+ setupEnv() {
54
+ // TODO: The insecure flag should be set by the shim instead of the SDK.
55
+ Object.entries(process.env).forEach(([key, value]) => {
56
+ if (key.startsWith("OTEL_") &&
57
+ key.endsWith("_ENDPOINT") &&
58
+ value?.startsWith("http://")) {
59
+ const insecure = key.replace(/_ENDPOINT$/, "_INSECURE");
60
+ if (process.env[insecure] === undefined) {
61
+ process.env[insecure] = "true";
62
+ }
63
+ }
64
+ });
65
+ }
66
+ }
@@ -0,0 +1,16 @@
1
+ import * as opentelemetry from "@opentelemetry/api";
2
+ import { Tracer } from "./tracer.js";
3
+ export declare function initialize(): void;
4
+ export declare function close(): Promise<void>;
5
+ /**
6
+ * Return a tracer to use with Dagger.
7
+ *
8
+ * The tracer is automatically initialized if not already done.
9
+ * As a conveniance function, you can use `withTracingSpan` that automatically close
10
+ * the span at the end of the function.
11
+ *
12
+ * You can add a custom name to the tracer based on your application.
13
+ */
14
+ export declare function getTracer(name?: string): Tracer;
15
+ export declare function getContext(): opentelemetry.Context;
16
+ //# sourceMappingURL=telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../../telemetry/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAGnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAMpC,wBAAgB,UAAU,SAEzB;AAED,wBAAsB,KAAK,kBAE1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAqB,GAAG,MAAM,CAG3D;AAED,wBAAgB,UAAU,0BAgBzB"}
@@ -0,0 +1,38 @@
1
+ import * as opentelemetry from "@opentelemetry/api";
2
+ import { DaggerOtelConfigurator } from "./init.js";
3
+ import { Tracer } from "./tracer.js";
4
+ const DAGGER_TRACER_NAME = "dagger.io/sdk.typescript";
5
+ const configurator = new DaggerOtelConfigurator();
6
+ export function initialize() {
7
+ configurator.initialize();
8
+ }
9
+ export async function close() {
10
+ await configurator.close();
11
+ }
12
+ /**
13
+ * Return a tracer to use with Dagger.
14
+ *
15
+ * The tracer is automatically initialized if not already done.
16
+ * As a conveniance function, you can use `withTracingSpan` that automatically close
17
+ * the span at the end of the function.
18
+ *
19
+ * You can add a custom name to the tracer based on your application.
20
+ */
21
+ export function getTracer(name = DAGGER_TRACER_NAME) {
22
+ initialize();
23
+ return new Tracer(name);
24
+ }
25
+ export function getContext() {
26
+ const ctx = opentelemetry.context.active();
27
+ const spanCtx = opentelemetry.trace.getSpanContext(ctx);
28
+ if (spanCtx && opentelemetry.trace.isSpanContextValid(spanCtx)) {
29
+ return ctx;
30
+ }
31
+ const parentID = process.env.TRACEPARENT;
32
+ if (parentID) {
33
+ return opentelemetry.propagation.extract(ctx, {
34
+ traceparent: parentID,
35
+ });
36
+ }
37
+ return ctx;
38
+ }
@@ -0,0 +1,32 @@
1
+ import * as opentelemetry from "@opentelemetry/api";
2
+ /**
3
+ * Tracer encapsulates the OpenTelemetry Tracer.
4
+ */
5
+ export declare class Tracer {
6
+ private tracer;
7
+ constructor(name: string);
8
+ startSpan(name: string, attributes?: opentelemetry.Attributes): opentelemetry.Span;
9
+ /**
10
+ * Execute the functions with a custom span with the given name using startActiveSpan.
11
+ * The function executed will use the parent context of the function (it can be another span
12
+ * or the main function).
13
+ *
14
+ * @param name The name of the span
15
+ * @param fn The functions to execute
16
+ *
17
+ * startActiveSpan returns the result of the executed functions.
18
+ *
19
+ * The span is automatically ended when the function is done.
20
+ * The span is automatically marked as an error if the function throws an error.
21
+ *
22
+ *
23
+ * @example
24
+ * ```
25
+ * return getTracer().startActiveSpan(name, async () => {
26
+ * return this.containerEcho("test").stdout()
27
+ * })
28
+ * ```
29
+ */
30
+ startActiveSpan<T>(name: string, fn: (span: opentelemetry.Span) => Promise<T>, attributes?: opentelemetry.Attributes): Promise<T>;
31
+ }
32
+ //# sourceMappingURL=tracer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../telemetry/tracer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAsB;gBAExB,IAAI,EAAE,MAAM;IAIjB,SAAS,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,aAAa,CAAC,UAAU,GACpC,aAAa,CAAC,IAAI;IAIrB;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,eAAe,CAAC,CAAC,EAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EAC5C,UAAU,CAAC,EAAE,aAAa,CAAC,UAAU;CAoBxC"}
@@ -0,0 +1,54 @@
1
+ import * as opentelemetry from "@opentelemetry/api";
2
+ /**
3
+ * Tracer encapsulates the OpenTelemetry Tracer.
4
+ */
5
+ export class Tracer {
6
+ tracer;
7
+ constructor(name) {
8
+ this.tracer = opentelemetry.trace.getTracer(name);
9
+ }
10
+ startSpan(name, attributes) {
11
+ return this.tracer.startSpan(name, { attributes });
12
+ }
13
+ /**
14
+ * Execute the functions with a custom span with the given name using startActiveSpan.
15
+ * The function executed will use the parent context of the function (it can be another span
16
+ * or the main function).
17
+ *
18
+ * @param name The name of the span
19
+ * @param fn The functions to execute
20
+ *
21
+ * startActiveSpan returns the result of the executed functions.
22
+ *
23
+ * The span is automatically ended when the function is done.
24
+ * The span is automatically marked as an error if the function throws an error.
25
+ *
26
+ *
27
+ * @example
28
+ * ```
29
+ * return getTracer().startActiveSpan(name, async () => {
30
+ * return this.containerEcho("test").stdout()
31
+ * })
32
+ * ```
33
+ */
34
+ async startActiveSpan(name, fn, attributes) {
35
+ return this.tracer.startActiveSpan(name, { attributes }, async (span) => {
36
+ try {
37
+ return await fn(span);
38
+ }
39
+ catch (e) {
40
+ if (e instanceof Error) {
41
+ span.recordException(e);
42
+ span.setStatus({
43
+ code: opentelemetry.SpanStatusCode.ERROR,
44
+ message: e.message,
45
+ });
46
+ }
47
+ throw e;
48
+ }
49
+ finally {
50
+ span.end();
51
+ }
52
+ });
53
+ }
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dagger.io/dagger",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "author": "hello@dagger.io",
5
5
  "license": "Apache-2.0",
6
6
  "types": "./dist/index.d.ts",
@@ -9,25 +9,32 @@
9
9
  "dist/"
10
10
  ],
11
11
  "exports": {
12
- ".": "./dist/index.js"
12
+ ".": "./dist/index.js",
13
+ "./telemetry": "./dist/telemetry/index.js"
13
14
  },
14
15
  "engines": {
15
16
  "node": ">=18"
16
17
  },
17
18
  "main": "dist/index.js",
18
19
  "dependencies": {
20
+ "@grpc/grpc-js": "^1.10.6",
19
21
  "@lifeomic/axios-fetch": "^3.0.1",
22
+ "@opentelemetry/api": "^1.8.0",
23
+ "@opentelemetry/exporter-trace-otlp-grpc": "^0.51.0",
24
+ "@opentelemetry/sdk-metrics": "^1.24.0",
25
+ "@opentelemetry/sdk-node": "^0.51.0",
26
+ "@opentelemetry/semantic-conventions": "^1.24.0",
20
27
  "adm-zip": "^0.5.10",
21
28
  "env-paths": "^3.0.0",
22
29
  "execa": "^8.0.1",
23
30
  "graphql": "^16.8.0",
24
31
  "graphql-request": "^6.1.0",
25
32
  "graphql-tag": "^2.12.6",
26
- "node-color-log": "^11.0.0",
33
+ "node-color-log": "^12.0.0",
27
34
  "node-fetch": "^3.3.1",
28
35
  "reflect-metadata": "^0.2.1",
29
- "tar": "^6.1.13",
30
- "typescript": "^5.3.3"
36
+ "tar": "^7.1.0",
37
+ "typescript": "^5.4.5"
31
38
  },
32
39
  "scripts": {
33
40
  "build": "tsc",
@@ -37,23 +44,25 @@
37
44
  "test:node": "mocha",
38
45
  "test:generate-scan": "tsx ./introspector/test/testdata/generate_expected_scan.ts",
39
46
  "lint": "yarn eslint --max-warnings=0 .",
40
- "fmt": "yarn eslint --fix .",
41
- "docs:lint": "yarn eslint -c .eslintrc-docs.cjs --max-warnings=0 --resolve-plugins-relative-to=./ --ext=.js,.ts,.mjs,.mts ../../docs/current_docs",
42
- "docs:fmt": "yarn eslint -c .eslintrc-docs.cjs --fix --resolve-plugins-relative-to=./ --ext=.js,.ts,.mjs,.mts ../../docs/current_docs ."
47
+ "fmt": "yarn eslint --max-warnings=0 --fix .",
48
+ "docs:lint": "cd ../../docs/current_docs && eslint -c ../../sdk/typescript/eslint-docs.config.js --max-warnings=0 ./**/*.ts",
49
+ "docs:fmt": "cd ../../docs/current_docs && eslint --fix -c ../../sdk/typescript/eslint-docs.config.js --max-warnings=0 ./**/*.ts"
43
50
  },
44
51
  "devDependencies": {
52
+ "@eslint/js": "^9.2.0",
45
53
  "@trivago/prettier-plugin-sort-imports": "^4.2.0",
46
54
  "@types/adm-zip": "^0.5.0",
47
55
  "@types/mocha": "latest",
48
56
  "@types/node": "~20",
49
57
  "@types/tar": "^6.1.4",
50
- "@typescript-eslint/eslint-plugin": "^5.62.0",
51
- "@typescript-eslint/parser": "^5.62.0",
52
- "eslint": "^8.57.0",
58
+ "@typescript-eslint/eslint-plugin": "^7.8.0",
59
+ "@typescript-eslint/parser": "^7.8.0",
60
+ "eslint": "^9.2.0",
53
61
  "eslint-config-prettier": "^9.1.0",
54
62
  "eslint-plugin-prettier": "^5.1.3",
55
63
  "mocha": "^10.2.0",
56
64
  "prettier": "^3.2.5",
57
- "ts-node": "^10.9.1"
65
+ "ts-node": "^10.9.1",
66
+ "typescript-eslint": "^7.8.0"
58
67
  }
59
68
  }