Skip to content

Commit

Permalink
Fix order of arguments in axiomTraceExporter
Browse files Browse the repository at this point in the history
- Make examples use Postgres
  • Loading branch information
bahlo committed Sep 29, 2022
1 parent bcf6760 commit 17ac73a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Running an example

1. Run `docker-compose up` to start a local Postgres server
2. Go into the folder and run `npm run start` to start the example
2 changes: 1 addition & 1 deletion examples/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "example on using prisma-axiom",
"main": "index.ts",
"scripts": {
"start": "ts-node index.ts"
"start": "cd ../.. && npm run build && cd - && prisma generate && prisma migrate dev --name init && ts-node index.ts"
},
"dependencies": {
"prisma-axiom": "../../dist",
Expand Down
4 changes: 2 additions & 2 deletions examples/extend-otel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "example on using prisma-axiom in a script",
"main": "index.ts",
"scripts": {
"start": "ts-node index.ts"
"start": "cd ../.. && npm run build && cd - && prisma generate && prisma migrate dev --name init && ts-node index.ts"
},
"dependencies": {
"@prisma/client": "^4.2.1",
Expand All @@ -15,4 +15,4 @@
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
}
}
}
4 changes: 1 addition & 3 deletions examples/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { PrismaClient } from '@prisma/client';

const client = new PrismaClient();

async function main(name: string) {
console.log(name)

async function main() {
await client.user.create({
data: {
name: 'Alice',
Expand Down
2 changes: 1 addition & 1 deletion examples/script/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "example on using prisma-axiom in a script",
"main": "index.ts",
"scripts": {
"start": "ts-node index.ts"
"start": "cd ../.. && npm run build && cd - && prisma generate && prisma migrate dev --name init && ts-node index.ts"
},
"dependencies": {
"prisma-axiom": "../../dist",
Expand Down
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const defaultConfig: AxiomConfig = {
additionalInstrumentations: [],
};

export default function withAxiom<T>(fn: (...args: any[]) => Promise<T>, config: AxiomConfig = defaultConfig): (...args: any[]) => Promise<T> {
export default function withAxiom<T>(
fn: (...args: any[]) => Promise<T>,
config: AxiomConfig = defaultConfig
): (...args: any[]) => Promise<T> {
// Merge provided config with default config to fall back to environment
// variables if not provided.
config = { ...defaultConfig, ...config };
Expand All @@ -39,7 +42,7 @@ export default function withAxiom<T>(fn: (...args: any[]) => Promise<T>, config:
}

const sdk = new NodeSDK({
traceExporter: axiomTraceExporter(config.axiomUrl, config.axiomToken),
traceExporter: axiomTraceExporter(config.axiomToken, config.axiomUrl),
instrumentations,
});

Expand All @@ -52,9 +55,9 @@ export default function withAxiom<T>(fn: (...args: any[]) => Promise<T>, config:
);

return async (...args: any[]) => {
await sdk.start()
await sdk.start();
const res = await fn(...args);
await sdk.shutdown();
return res;
}
};
}

0 comments on commit 17ac73a

Please sign in to comment.