You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2023/09/04 03:36:57 UTC

[skywalking-nodejs] branch master updated: feat: add deadline for trace request (#118)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-nodejs.git


The following commit(s) were added to refs/heads/master by this push:
     new c40e46d  feat: add deadline for trace request (#118)
c40e46d is described below

commit c40e46d95460d25508168b3d7d16bf05fbea3064
Author: Eros Zhao <zy...@gmail.com>
AuthorDate: Mon Sep 4 11:36:51 2023 +0800

    feat: add deadline for trace request (#118)
---
 README.md                                            |  2 ++
 src/agent/protocol/grpc/clients/TraceReportClient.ts | 16 ++++++++++------
 src/config/AgentConfig.ts                            |  4 ++++
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 935a5cd..4b19e74 100644
--- a/README.md
+++ b/README.md
@@ -69,6 +69,8 @@ Environment Variable | Description | Default
 | `SW_AWS_LAMBDA_CHAIN` | Pass trace ID to AWS Lambda function in its parameters (to allow linking). Only use if both caller and callee will be instrumented. | `false` |
 | `SW_AWS_SQS_CHECK_BODY` | Incoming SQS messages check inside the body for trace ID in order to allow linking outgoing SNS messages to incoming SQS. | `false` |
 | `SW_AGENT_MAX_BUFFER_SIZE` | The maximum buffer size before sending the segment data to backend | `'1000'` |
+| `SW_AGENT_TRACE_TIMEOUT` | The timeout for trace requests to backend services | `'10000'` |
+
 
 Note that the various ignore options like `SW_IGNORE_SUFFIX`, `SW_TRACE_IGNORE_PATH` and `SW_HTTP_IGNORE_METHOD` as well as endpoints which are not recorded due to exceeding `SW_AGENT_MAX_BUFFER_SIZE` all propagate their ignored status downstream to any other endpoints they may call. If that endpoint is running the Node Skywalking agent then regardless of its ignore settings it will not be recorded since its upstream parent was not recorded. This allows the elimination of entire trees of [...]
 
diff --git a/src/agent/protocol/grpc/clients/TraceReportClient.ts b/src/agent/protocol/grpc/clients/TraceReportClient.ts
index 1ef0003..3f6f102 100755
--- a/src/agent/protocol/grpc/clients/TraceReportClient.ts
+++ b/src/agent/protocol/grpc/clients/TraceReportClient.ts
@@ -60,13 +60,17 @@ export default class TraceReportClient implements Client {
         return;
       }
 
-      const stream = this.reporterClient.collect(AuthInterceptor(), (error, _) => {
-        if (error) {
-          logger.error('Failed to report trace data', error);
-        }
+      const stream = this.reporterClient.collect(
+        AuthInterceptor(),
+        { deadline: Date.now() + config.traceTimeout },
+        (error, _) => {
+          if (error) {
+            logger.error('Failed to report trace data', error);
+          }
 
-        if (callback) callback();
-      });
+          if (callback) callback();
+        },
+      );
 
       try {
         for (const segment of this.buffer) {
diff --git a/src/config/AgentConfig.ts b/src/config/AgentConfig.ts
index ad82b59..ca33587 100644
--- a/src/config/AgentConfig.ts
+++ b/src/config/AgentConfig.ts
@@ -42,6 +42,7 @@ export type AgentConfig = {
   reDisablePlugins?: RegExp;
   reIgnoreOperation?: RegExp;
   reHttpIgnoreMethod?: RegExp;
+  traceTimeout?: number;
 };
 
 export function finalizeConfig(config: AgentConfig): void {
@@ -136,6 +137,9 @@ const _config = {
   reDisablePlugins: RegExp(''), // temporary placeholder so Typescript doesn't throw a fit
   reIgnoreOperation: RegExp(''),
   reHttpIgnoreMethod: RegExp(''),
+  traceTimeout: Number.isSafeInteger(process.env.SW_AGENT_TRACE_TIMEOUT)
+    ? Number.parseInt(process.env.SW_AGENT_TRACE_TIMEOUT as string, 10)
+    : 10 * 1000,
 };
 
 export default _config;