Skip to content

Commit

Permalink
Merge pull request #78 from appoptics/cc/NH-33233
Browse files Browse the repository at this point in the history
NH-33233: Refactor Agent API
  • Loading branch information
cleverchuk authored Mar 2, 2023
2 parents 5a1d24d + e2436ad commit e73f4c6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 46 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.appoptics.api.ext;

import java.util.logging.Logger;

public class SolarWindsAgent {
private SolarWindsAgent() {
}

private static final Logger logger = Logger.getLogger(SolarWindsAgent.class.getName());

private static boolean isAgentReady = false;

static {
try {
Class.forName("com.appoptics.opentelemetry.core.CustomTransactionNameDict");
isAgentReady = true;
logger.info("The SolarWinds APM agent and the SDK is available.");
} catch (ClassNotFoundException | NoClassDefFoundError | NoSuchMethodError e) {
logger.warning("The SolarWinds APM Agent is not available. The SDK will be no-op.");
}
}

public static boolean setTransactionName(String transactionName) {
if (!isAgentReady) {
return false;
}
return Transaction.setName(transactionName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.appoptics.api.ext;

import com.appoptics.opentelemetry.core.CustomTransactionNameDict;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.context.Context;

/**
* The API to set the custom transaction name for the current trace. It returns false if the current trace is not valid
* or not sampled.
*/
class Transaction {

/**
* Set the transaction name of the current trace.
*
* @param name the custom transaction name to be set to the current trace
* @return {@code true} if the transaction name is successfully set, or {@code false} if the transaction name is not set because the span is invalid or the not sampled.
*/
static boolean setName(String name) {
Context context = Context.current();
Span span = Span.fromContext(context);
SpanContext spanContext = span.getSpanContext();

if (!(spanContext.isValid() && spanContext.isSampled())) {
return false;
}
CustomTransactionNameDict.set(spanContext.getTraceId(), name);

return true;
}
}

0 comments on commit e73f4c6

Please sign in to comment.