Skip to content

Conversation

chriswlai
Copy link

@chriswlai chriswlai commented Jun 26, 2025

Description

Adds new MLAgentTracer class to capture traces within ML-commons and settings to disable or enable tracing.

Screenshot 2025-07-14 at 2 16 39 PM

Related Issues

Resolves #3971

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@chriswlai chriswlai changed the title Feature/mlagenttracer MLAgentTracer Class Jun 26, 2025
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval June 26, 2025 21:20 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval June 26, 2025 21:20 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval June 26, 2025 21:20 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval June 26, 2025 21:20 — with GitHub Actions Failure
Copy link
Contributor

@brianf-aws brianf-aws left a comment

Choose a reason for hiding this comment

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

Left a few comments, I'm seeing the commit history is a criss crossed with some commits can we rebase with the opensearch-project:feature/agent-tracing branch to see if it fixes it?

Also lets make sure to sign off our commits using -s as in git commit -s -m "<your Message>" you can see this is why DCO is complaining

return tracer;
}

static void resetForTest() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use a @ VisibleForTesting annotation also what else do we need to reset?


public static synchronized MLAgentTracer getInstance() {
if (instance == null) {
throw new IllegalStateException("MLAgentTracer is not initialized. Call initialize() first or check feature flag.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets be specific which feature flag needs to be flipped
plugins.ml_commons.agent_tracing_feature_enabled or
plugins.ml_commons.agent_tracing_enabled?

As a side note how can I tell what setting I need to switch on?

@chriswlai chriswlai force-pushed the feature/mlagenttracer branch 2 times, most recently from d4cca33 to 6eb634d Compare June 26, 2025 22:15
@chriswlai chriswlai force-pushed the feature/mlagenttracer branch from 6eb634d to c712e12 Compare June 26, 2025 22:21
Signed-off-by: chrislai <[email protected]>
@chriswlai chriswlai temporarily deployed to ml-commons-cicd-env-require-approval June 26, 2025 22:27 — with GitHub Actions Inactive
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval June 26, 2025 22:27 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval June 26, 2025 22:27 — with GitHub Actions Error
Signed-off-by: chrislai <[email protected]>
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 10, 2025 22:59 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 10, 2025 22:59 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 10, 2025 22:59 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 10, 2025 22:59 — with GitHub Actions Failure
Signed-off-by: chrislai <[email protected]>
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 10, 2025 23:14 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 10, 2025 23:14 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 10, 2025 23:14 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 10, 2025 23:14 — with GitHub Actions Failure
Signed-off-by: chrislai <[email protected]>
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 12, 2025 00:20 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 12, 2025 00:20 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 12, 2025 00:20 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 12, 2025 00:20 — with GitHub Actions Failure
* The returned span should be passed to {@link #endSpan(Span)} when the
* operation completes.
*/
public abstract Span startSpan(String name, Map<String, String> attributes, Span parentSpan);
Copy link
Collaborator

Choose a reason for hiding this comment

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

what do you think of creating an overloaded method for spans without parents:
startSpan(String name, Map<String, String> attributes);

This internally can call the startSpan method with null parent

}
SpanCreationContext context = SpanCreationContext.server().name(name).attributes(attrBuilder);
Span newSpan;
if (name != null && name.startsWith(AGENT_TASK_SPAN) && !(tracer instanceof NoopTracer)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

any reason for checking if (!tracer instance of NoopTracer)

i would assume since they are both tracer objects, you could simply use the methods but just that internally NoopTracer wouldn't do anything

Copy link
Author

Choose a reason for hiding this comment

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

We check for NoopTracer since although it gracefully handles public methods of Tracer, we use reflection to access internals (for custom span creation and injection/extraction) and NoopTracer doesn't have these so it will give a NoSuchFieldException.

The agent execution will still run as normal, but I'm just checking to avoid the exception.

* @param carrier The map to inject context into. The span context will be added
* as key-value pairs to this map. Must not be null.
*/
public void injectSpanContext(Span span, Map<String, String> carrier) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

when will these method be used?

  • injectSpanContext
  • extractSpanContext

Copy link
Author

Choose a reason for hiding this comment

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

These are used in Plan-Execute-Reflect and Conversational agents to connect the conversational agent span with the p-e-r agent span

Signed-off-by: chrislai <[email protected]>
@chriswlai chriswlai temporarily deployed to ml-commons-cicd-env-require-approval July 14, 2025 19:46 — with GitHub Actions Inactive
@chriswlai chriswlai temporarily deployed to ml-commons-cicd-env-require-approval July 14, 2025 19:46 — with GitHub Actions Inactive
@chriswlai chriswlai temporarily deployed to ml-commons-cicd-env-require-approval July 14, 2025 19:46 — with GitHub Actions Inactive
@chriswlai chriswlai temporarily deployed to ml-commons-cicd-env-require-approval July 14, 2025 19:46 — with GitHub Actions Inactive
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 14, 2025 20:50 — with GitHub Actions Failure
@chriswlai chriswlai had a problem deploying to ml-commons-cicd-env-require-approval July 14, 2025 20:50 — with GitHub Actions Failure
@mingshl mingshl merged commit 1abc5fb into opensearch-project:feature/agent-tracing Jul 15, 2025
11 of 13 checks passed
chriswlai added a commit to chriswlai/ml-commons that referenced this pull request Aug 7, 2025
* adding agent tracing to mlplugin

Signed-off-by: chrislai <[email protected]>

* add settings and clean code

Signed-off-by: chrislai <[email protected]>

* add tests

Signed-off-by: chrislai <[email protected]>

* cr fixes

Signed-off-by: chrislai <[email protected]>

* tests message fix and spotlessApply

Signed-off-by: chrislai <[email protected]>

* spotlessApply

Signed-off-by: chrislai <[email protected]>

* add tests

Signed-off-by: chrislai <[email protected]>

* fix comments

Signed-off-by: chrislai <[email protected]>

* add visiblefortesting

Signed-off-by: chrislai <[email protected]>

* address comments

Signed-off-by: chrislai <[email protected]>

* javadoc

Signed-off-by: chrislai <[email protected]>

* more tests

Signed-off-by: chrislai <[email protected]>

* more class fixes

Signed-off-by: chrislai <[email protected]>

* overloaded method

Signed-off-by: chrislai <[email protected]>

---------

Signed-off-by: chrislai <[email protected]>
chriswlai added a commit to chriswlai/ml-commons that referenced this pull request Aug 9, 2025
* adding agent tracing to mlplugin

Signed-off-by: chrislai <[email protected]>

* add settings and clean code

Signed-off-by: chrislai <[email protected]>

* add tests

Signed-off-by: chrislai <[email protected]>

* cr fixes

Signed-off-by: chrislai <[email protected]>

* tests message fix and spotlessApply

Signed-off-by: chrislai <[email protected]>

* spotlessApply

Signed-off-by: chrislai <[email protected]>

* add tests

Signed-off-by: chrislai <[email protected]>

* fix comments

Signed-off-by: chrislai <[email protected]>

* add visiblefortesting

Signed-off-by: chrislai <[email protected]>

* address comments

Signed-off-by: chrislai <[email protected]>

* javadoc

Signed-off-by: chrislai <[email protected]>

* more tests

Signed-off-by: chrislai <[email protected]>

* more class fixes

Signed-off-by: chrislai <[email protected]>

* overloaded method

Signed-off-by: chrislai <[email protected]>

---------

Signed-off-by: chrislai <[email protected]>
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.

4 participants