@vercel/otel 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.
@@ -0,0 +1,33 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ tags:
8
+ - "!*"
9
+ pull_request:
10
+
11
+ env:
12
+ NODE_VERSION: "16"
13
+ TURBO_REMOTE_ONLY: "true"
14
+ TURBO_TEAM: "vercel"
15
+ TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
16
+
17
+ concurrency:
18
+ group: ${{ github.workflow }}-${{ github.ref }}
19
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
20
+
21
+ jobs:
22
+ build:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v3
26
+ with:
27
+ fetch-depth: 2
28
+ - uses: actions/setup-node@v3
29
+ with:
30
+ node-version: ${{ env.NODE_VERSION }}
31
+ - run: npm i -g pnpm@7.24.2
32
+ - run: pnpm install
33
+ - run: pnpm build
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Vercel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ <!--
2
+ PROMPT for GPT-4:
3
+ Write me a README.md for package vercel/otel that helps people get started by setting up their exporter and trace provider for them and false bundles all OPen Telemetry apis in a single package.
4
+ It's not a powerful as using raw APIS, but It should be enough for most cases.
5
+
6
+ This package exports function `register()` that registers open telemetry provider with a HTTP exporter.
7
+ Register function takes one argument, it's string and it's a service name. It will be used as the app name in many OpenTelemetry backends.
8
+ This package also reexports `@opentelemetry/api` and `@opentelemetry/semantics`.
9
+
10
+ Use that hip style for Readme that many JS devs use. Keep it concise.
11
+ -->
12
+
13
+ # 🚀 Vercel Otel
14
+
15
+ [![npm](https://img.shields.io/npm/v/vercel/otel.svg)](https://www.npmjs.com/package/vercel/otel)
16
+
17
+ `vercel/otel` is a simple and easy-to-use package that sets up your trace provider and exporter, and bundles all OpenTelemetry APIs in a single package. It's not as powerful as using raw APIs, but it should be enough for most cases.
18
+
19
+ 💡 Use this package to quickly instrument your applications and get started with OpenTelemetry!
20
+
21
+ ## 📦 Installation
22
+
23
+ ```sh
24
+ npm install vercel/otel
25
+ ```
26
+
27
+ ## 📚 Usage
28
+
29
+ ```javascript
30
+ const { register, trace } = require("vercel/otel");
31
+
32
+ // Register the OpenTelemetry provider with an HTTP exporter
33
+ register("your-service-name");
34
+
35
+ // Now you can use the OpenTelemetry APIs
36
+ const span = trace.getTracer("your-component").startSpan("your-operation");
37
+ ```
38
+
39
+ ## 📖 API Reference
40
+
41
+ ### `register(serviceName: string)`
42
+
43
+ Registers the OpenTelemetry provider with an HTTP exporter using the given service name.
44
+ This is all that is needed to trace your app on Vercel.
45
+
46
+ - `serviceName`: The name of your service, used as the app name in many OpenTelemetry backends.
47
+
48
+ ### Re-exported APIs
49
+
50
+ This package re-exports everything from `@opentelemetry/api`. Refer to the official [OpenTelemetry API documentation](https://opentelemetry.io/docs/instrumentation/js/) for details on how to use these APIs.
51
+
52
+ ## 📄 License
53
+
54
+ [MIT](LICENSE)
55
+
56
+ ---
57
+
58
+ Made with 💖 by the Vercel. Happy tracing! 📈
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@vercel/otel",
3
+ "version": "0.0.1",
4
+ "description": "Vercel wrapper around OpenTelemetry APIs",
5
+ "types": "./dist/index.node.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "edge": {
9
+ "types": "./dist/index.edge.d.ts",
10
+ "default": "./dist/index.edge.js"
11
+ },
12
+ "edge-light": {
13
+ "types": "./dist/index.edge.d.ts",
14
+ "default": "./dist/index.edge.js"
15
+ },
16
+ "worker": {
17
+ "types": "./dist/index.edge.d.ts",
18
+ "default": "./dist/index.edge.js"
19
+ },
20
+ "workerd": {
21
+ "types": "./dist/index.edge.d.ts",
22
+ "default": "./dist/index.edge.js"
23
+ },
24
+ "import": {
25
+ "types": "./dist/index.node.d.ts",
26
+ "default": "./dist/index.node.js"
27
+ },
28
+ "node": {
29
+ "types": "./dist/index.node.d.ts",
30
+ "default": "./dist/index.node.js"
31
+ }
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/vercel/vercel.git",
38
+ "directory": "packages/otel"
39
+ },
40
+ "scripts": {
41
+ "build": "pnpm build:node && pnpm build:edge",
42
+ "build:node": "tsc --project tsconfig.node.json",
43
+ "build:edge": "tsc --project tsconfig.edge.json"
44
+ },
45
+ "license": "MIT",
46
+ "devDependencies": {
47
+ "@types/node": "14.18.33",
48
+ "typescript": "^4.8.4"
49
+ },
50
+ "dependencies": {
51
+ "@opentelemetry/api": "1.4.1",
52
+ "@opentelemetry/exporter-trace-otlp-http": "0.35.1",
53
+ "@opentelemetry/resources": "1.9.1",
54
+ "@opentelemetry/sdk-trace-node": "1.9.1",
55
+ "@opentelemetry/semantic-conventions": "1.9.1"
56
+ }
57
+ }
@@ -0,0 +1,4 @@
1
+ export const registerOTel = (serviceName: string) => {
2
+ void serviceName;
3
+ // We don't support OpenTelemetry on edge.
4
+ };
@@ -0,0 +1,24 @@
1
+ export * from "@opentelemetry/api";
2
+
3
+ import { Resource } from "@opentelemetry/resources";
4
+ import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
5
+ import {
6
+ NodeTracerProvider,
7
+ SimpleSpanProcessor,
8
+ } from "@opentelemetry/sdk-trace-node";
9
+
10
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
11
+
12
+ export const registerOTel = (serviceName: string) => {
13
+ const provider = new NodeTracerProvider({
14
+ resource: new Resource({
15
+ [SemanticResourceAttributes.SERVICE_NAME]: serviceName,
16
+ }),
17
+ });
18
+
19
+ provider.register();
20
+
21
+ provider.addSpanProcessor(new SimpleSpanProcessor(new OTLPTraceExporter({})));
22
+
23
+ return provider;
24
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "lib": ["ES2020", "dom"]
5
+ },
6
+ "files": ["./src/index.edge.ts"]
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "lib": ["ES2020", "dom"]
5
+ },
6
+ "files": ["./src/index.edge.ts"]
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationMap": true,
5
+ "esModuleInterop": true,
6
+ "lib": ["ES2020"],
7
+ "module": "commonjs",
8
+ "moduleResolution": "node",
9
+ "noEmitOnError": true,
10
+ "noFallthroughCasesInSwitch": true,
11
+ "noImplicitReturns": true,
12
+ "noUnusedLocals": true,
13
+ "noUnusedParameters": true,
14
+ "outDir": "./dist",
15
+ "types": ["node"],
16
+ "strict": true,
17
+ "sourceMap": true,
18
+ "target": "ES2020"
19
+ },
20
+ "include": ["src/**/*"],
21
+ "exclude": ["node_modules"]
22
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ // There is a bug in OTEL that requires us to add dom types: https://github.com/open-telemetry/opentelemetry-js/issues/3580
5
+ "lib": ["ES2020", "dom"]
6
+ },
7
+ "files": ["./src/index.node.ts"]
8
+ }