-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from appoptics/cc/NH-33233
NH-33233: Refactor Agent API
- Loading branch information
Showing
3 changed files
with
61 additions
and
46 deletions.
There are no files selected for viewing
46 changes: 0 additions & 46 deletions
46
solarwinds-otel-sdk/src/main/java/com/appoptics/api/ext/CustomTransactionName.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
solarwinds-otel-sdk/src/main/java/com/appoptics/api/ext/SolarWindsAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
solarwinds-otel-sdk/src/main/java/com/appoptics/api/ext/Transaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |