Skip to content

Commit

Permalink
Fix service name (#3779)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riron authored Nov 28, 2024
1 parent fdd6c71 commit 0295b5f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 47 deletions.
6 changes: 3 additions & 3 deletions libs/back/tracer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import {
} from "@opentelemetry/semantic-conventions";
import { PrismaInstrumentation } from "@prisma/instrumentation";
import { ElasticsearchInstrumentation } from "opentelemetry-instrumentation-elasticsearch";
import { findPkg } from "./pkg";
import { getAppRootFolderName } from "./utils";

if (process.env.NODE_ENV !== "test" && !process.env.OTEL_SDK_DISABLED) {
const packageJson = findPkg();
const serviceName = getAppRootFolderName();

const sdk = new NodeSDK({
resource: new Resource({
[SEMRESATTRS_SERVICE_NAME]: packageJson.name || "trackdechets",
[SEMRESATTRS_SERVICE_NAME]: serviceName || "trackdechets",
[SEMRESATTRS_DEPLOYMENT_ENVIRONMENT]:
process.env.OTEL_ENVIRONMENT || "development",
[SEMRESATTRS_CLOUD_REGION]: process.env.REGION_NAME,
Expand Down
44 changes: 0 additions & 44 deletions libs/back/tracer/src/pkg.ts

This file was deleted.

9 changes: 9 additions & 0 deletions libs/back/tracer/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { dirname, basename } from "node:path";

export function getAppRootFolderName() {
const executedFile = process.argv[1]; // path/to/your/script.js
const entryPointDir = dirname(executedFile); // => path/to/your
const folder = basename(entryPointDir); // => your

return folder;
}

0 comments on commit 0295b5f

Please sign in to comment.