Skip to content

HPCC-32372 Support tracing from testsocket #19613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

rpastrana
Copy link
Member

@rpastrana rpastrana commented Mar 12, 2025

  • Adds testsocket option to generate and propagate OTel based trace context
  • Adds option to customize JTrace

Type of change:

  • This change is a bug fix (non-breaking change which fixes an issue).
  • This change is a new feature (non-breaking change which adds functionality).
  • This change improves the code (refactor or other change that does not change the functionality)
  • This change fixes warnings (the fix does not alter the functionality or the generated code)
  • This change is a breaking change (fix or feature that will cause existing behavior to change).
  • This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • My code follows the code style of this project.
    • My code does not create any new warnings from compiler, build system, or lint.
  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit is signed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly, or...
    • I have created a JIRA ticket to update the documentation.
    • Any new interfaces or exported functions are appropriately commented.
  • I have read the CONTRIBUTORS document.
  • The change has been fully tested:
    • I have added tests to cover my changes.
    • All new and existing tests passed.
    • I have checked that this change does not introduce memory leaks.
    • I have used Valgrind or similar tools to check for potential issues.
  • I have given due consideration to all of the following potential concerns:
    • Scalability
    • Performance
    • Security
    • Thread-safety
    • Cloud-compatibility
    • Premature optimization
    • Existing deployed queries will not be broken
    • This change fixes the problem, not just the symptom
    • The target branch of this pull request is appropriate for such a change.
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised JIRA issues to address them separately
  • This is a user interface / front-end modification
    • I have tested my changes in multiple modern browsers
    • The component(s) render as expected

Smoketest:

  • Send notifications about my Pull Request position in Smoketest queue.
  • Test my draft Pull Request.

Testing:

Copy link

Jira Issue: https://hpccsystems.atlassian.net//browse/HPCC-32372

Jirabot Action Result:
Workflow Transition To: Merge Pending
Updated PR

@rpastrana rpastrana requested a review from Copilot March 12, 2025 18:04
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

@rpastrana rpastrana force-pushed the HPCC-32372-testsocket-tracing branch from 3bd2f8c to 3a0e4b1 Compare March 12, 2025 18:47
@rpastrana rpastrana requested a review from mckellyln March 12, 2025 18:49
@rpastrana
Copy link
Member Author

Disclaimer, if custom JTrace configuration is provided, we should expect JLOG output akin to this:
00000000 OPR 2025-03-12 13:36:37.381 710123 710123 "Exporter type: OTLP-GRPC"
00000001 OPR 2025-03-12 13:36:37.381 710123 710123 "Tracing exporter set to OTLP/GRPC to: (192.168.68.111:4317/)"

and also, potential OTel export debug info such as:
00000003 OPR 2025-03-12 13:36:58.858 710123 710247 "ERROR: JTrace: [OTLP TRACE GRPC Exporter] Export() failed with status_code: "UNAVAILABLE" error_message: "failed to connect to all addresses; last error: UNKNOWN: ipv4:192.168.68.111:4317: Failed to connect to remote host: Connection refused""

Also, if debug build, Jtrace log exporter will be automatically enabled and will generate output such as:
00000002 MON 2025-03-12 13:36:56.571 710123 710123 "{ "type": "span", "name": "testsocket_sendQuery", "trace_id": "9bc7727c61d90e3bf06b5fe222199e3d", "span_id": "c996a62a62b5cdd5", "start": 1741800997417554077, "duration": 19161849004, "parent_span_id": "093bde7626153368" }"

Also, the preexisting "trace" file will contain the resulting trace id

@rpastrana
Copy link
Member Author

@mckellyln please review

@rpastrana
Copy link
Member Author

Sample program args:
"program": "${workspaceFolder}/build/Debug/bin/testsocket",
"args": [
"localhost:9876", "-gcs", "-ctc" "{global: {tracing: {disable: false, resourceAttributes: {deploymentEnvironment: development}, exporters: [{type: OTLP-GRPC, endpoint: '192.168.68.111:4317/', useSslCredentials: false}]}}}", "-f", "/home/ubuntu/GIT/roxietracetest.ecl"
],
where roxietracetest.ecl: <_trace>00-5a8fea933a38ef0aab31d2c1008675d6-f186c3292b4308e9-01Jf4xTnd5VvXeH8PQGM8NnGJf4xTngoqZU9j99iBnsXYR</_trace>33434

}
else if (strieq(argv[arg], "-ctc"))
{
tracingConfig.set(argv[++arg]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to check if ++arg doesnt >= argc, but we dont check that everywhere above like we should.

@rpastrana rpastrana requested a review from mckellyln March 18, 2025 18:07
@@ -619,8 +623,19 @@ int doSendQuery(const char * ip, unsigned port, const char * base)
newQuery.appendf("</%sRequest></Body></Envelope>", queryName);
base = newQuery.str();
}

StringBuffer tpHeader;
Owned<IProperties> retrievedClientHeaders = createProperties();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this move to inside the if below, since retrievedClientHeaders is only used in the if block ?
Doesnt really make a difference tho.

Copy link
Contributor

@mckellyln mckellyln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.
Just one small comment.
Good to squash.

@rpastrana rpastrana force-pushed the HPCC-32372-testsocket-tracing branch from 2758cb0 to 4863882 Compare March 21, 2025 15:13
@rpastrana
Copy link
Member Author

Suggested change incorporated, and squashed.
@ghalliday ready for merge.

Copy link
Member

@ghalliday ghalliday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpastrana Looks useful. A couple of trivial comments, one suggestion for a simpler implementation and a couple of leaks.


if (retrievedClientHeaders->hasProp("traceparent"))
{
//disassemble xml in oder to inject _trace header
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: order

ForEach(*traceElemets)
{
IPTree &traceHeaderElem = traceElemets->query();
if (strcmp(traceHeaderElem.queryName(), "traceparent") != 0) //if not _trace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment references the wrong label.


fullQuery.setf("<%s><_trace><traceparent>%s</traceparent>", queryName, retrievedClientHeaders->queryProp("traceparent"));

IPropertyTree * traceHeader = p ->queryPropTree("_trace");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work (and be simpler) to code as:

if (traceHeader)
    traceHeader->setProp("traceparent", retrievedClientHeaders->queryProp("traceparent");

and then convert the whole property tree to xml again?

}
else
{
serverSpan.set(getNullSpan());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will leak - it should be setown


initTraceManager("testsocket", traceConfig, nullptr);

serverSpan.set(queryTraceManager().createServerSpan("testsocket_server", nullptr)); //can we avoid creating a server span?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will leak, it should be setown

@rpastrana rpastrana requested a review from ghalliday March 31, 2025 18:53
Copy link
Member

@ghalliday ghalliday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpastrana looks good, please squash

IPropertyTree * traceHeader = p ->queryPropTree("_trace");

if (traceHeader)
IPropertyTree * traceHeaderTree = fullQueryTree->queryPropTree("_trace");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future, simpler would be

                IPropertyTree * traceHeaderTree = ensurePTree(fullQueryTree, "_trace");
                traceHeaderTree->setProp("traceparent", retrievedClientHeaders->queryProp("traceparent"));

- Adds testsocket option to generate and propagate OTel based trace context
- Adds option to customize JTrace
- Tests for valid yaml
- Updates usage message

Signed-off-by: Rodrigo Pastrana <[email protected]>
@rpastrana rpastrana force-pushed the HPCC-32372-testsocket-tracing branch from 683f5a6 to 65b52b6 Compare April 1, 2025 14:25
@rpastrana
Copy link
Member Author

commits are squashed.

@ghalliday ghalliday merged commit 86de2d5 into hpcc-systems:candidate-9.10.x Apr 3, 2025
50 checks passed
Copy link

github-actions bot commented Apr 3, 2025

Jirabot Action Result:
Added fix version: 9.10.18
Workflow Transition: 'Resolve issue'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants