Skip to content

Commit

Permalink
fix dd trace log and trace correlation (#862)
Browse files Browse the repository at this point in the history
* fix dd trace log and trace corelation

* update

* update
  • Loading branch information
shunjizhan authored Oct 10, 2023
1 parent 63fbfec commit 0518b31
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
21 changes: 17 additions & 4 deletions packages/eth-rpc-adapter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,35 @@ RUN unlink /usr/bin/python && \

COPY . .
RUN yarn install --immutable
RUN yarn workspace @acala-network/eth-rpc-adapter ncc:pack
RUN yarn build


# =============

FROM node:16-alpine
LABEL maintainer="[email protected]"

COPY --from=builder /app/packages/eth-rpc-adapter/dist /app
COPY --from=builder /app/package.json /app/.yarnrc.yml /app/
COPY --from=builder /app/node_modules /app/node_modules

WORKDIR /app
COPY --from=builder /app/packages/eth-rpc-adapter/package.json /app/packages/eth-rpc-adapter/package.json
COPY --from=builder /app/packages/eth-transactions/package.json /app/packages/eth-transactions/package.json
COPY --from=builder /app/packages/eth-providers/package.json /app/packages/eth-providers/package.json

COPY --from=builder /app/packages/eth-rpc-adapter/lib /app/packages/eth-rpc-adapter/lib
COPY --from=builder /app/packages/eth-transactions/lib /app/packages/eth-transactions/lib
COPY --from=builder /app/packages/eth-providers/lib /app/packages/eth-providers/lib

COPY --from=builder /app/packages/eth-rpc-adapter/node_modules /app/packages/eth-rpc-adapter/node_modules
COPY --from=builder /app/packages/eth-transactions/node_modules /app/packages/eth-transactions/node_modules
# COPY --from=builder /app/packages/eth-providers/node_modules /app/packages/eth-providers/node_modules # don't exist

WORKDIR /app/packages/eth-rpc-adapter

EXPOSE 8545

USER node

ENV NODE_ENV=production

ENTRYPOINT ["node", "index.js" ]
ENTRYPOINT ["node", "lib/index.js"]
13 changes: 8 additions & 5 deletions packages/eth-rpc-adapter/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import tracer from 'dd-trace';
import { Eip1193Bridge } from './eip1193-bridge';
import { InternalError, InvalidParams, JSONRPCError, MethodNotFound } from './errors';
import { JsonRpcResponse } from './server';
import { shouldNotTrace } from './utils/datadog';
export class Router {
readonly #bridge: Eip1193Bridge;

Expand All @@ -16,11 +17,13 @@ export class Router {
public async call(methodName: string, params: unknown[], ws?: WebSocket): Promise<Partial<JsonRpcResponse>> {
if (this.#bridge.isMethodImplemented(methodName)) {
try {
const result = await tracer.trace(
'eth_rpc_call',
{ resource: methodName },
() => this.#bridge.send(methodName, params, ws)
);
const result = shouldNotTrace(methodName)
? await this.#bridge.send(methodName, params, ws)
: await tracer.trace(
'eth_rpc_call',
{ resource: methodName },
() => this.#bridge.send(methodName, params, ws)
);

return { result };
} catch (err: any) {
Expand Down
8 changes: 4 additions & 4 deletions packages/eth-rpc-adapter/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default class EthRpcServer {
}

private async httpHandler(req: any, res: http.ServerResponse, next: (err?: any) => void): Promise<void> {
logger.debug(req.body, 'incoming request');
logger.debug(req.body, ' request');

let result = null;
try {
Expand All @@ -175,7 +175,7 @@ export default class EthRpcServer {
return next(e);
}

logger.debug(result, 'request completed');
logger.debug(result, '✨ response');

res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(result));
Expand All @@ -197,7 +197,7 @@ export default class EthRpcServer {
return;
}

logger.debug(req, 'ws incoming request');
logger.debug(req, '⬇ ws request');

let result = null;

Expand All @@ -214,7 +214,7 @@ export default class EthRpcServer {
result = await this.baseHandler(req, ws);
}

logger.debug(result, 'ws request completed');
logger.debug(result, 'ws response');

ws.send(JSON.stringify(result));
}
Expand Down
4 changes: 4 additions & 0 deletions packages/eth-rpc-adapter/src/utils/datadog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const DONT_TRACE_ETH_RPCS = ['net_health'];

// we can also config these in dd agent, but with code it is more flexible
export const shouldNotTrace = (ethRpcName: string) => DONT_TRACE_ETH_RPCS.includes(ethRpcName);

0 comments on commit 0518b31

Please sign in to comment.