Skip to content

Commit 24cc7c1

Browse files
committed
fix README.md
1 parent bbd1b0f commit 24cc7c1

File tree

1 file changed

+48
-25
lines changed

1 file changed

+48
-25
lines changed

README.md

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,37 @@ Additionally you should/have to ensure, that you have set a `LoggingCallback`. F
4747

4848
Common concepts of the Dynatrace OneAgent SDK concepts are explained the [Dynatrace OneAgent SDK repository](https://github.com/Dynatrace/OneAgent-SDK).
4949

50+
## Get an Api object
51+
52+
Use OneAgentSDKFactory.createInstance() to obtain an OneAgentSDK instance. You should reuse this object over the whole application
53+
and if possible JVM lifetime:
54+
55+
```Java
56+
OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
57+
switch (oneAgentSdk.getCurrentState()) {
58+
case ACTIVE:
59+
break;
60+
case PERMANENTLY_INACTIVE:
61+
break;
62+
case TEMPORARILY_INACTIVE:
63+
break;
64+
default:
65+
break;
66+
}
67+
```
68+
69+
It is good practice to check the SDK state regularly as it may change at every point of time (except PERMANENTLY_INACTIVE never changes over JVM lifetime).
70+
5071
## Common concepts: Tracers
5172

5273
To trace any kind of call you first need to create a Tracer. The Tracer object represents the logical and physical endpoint that you want to call. A Tracer serves two purposes. First to time the call (duraction, cpu and more) and report errors. That is why each Tracer has these three methods. The error method must be called only once, and it must be in between start and end.
5374

5475
```Java
55-
void start();
56-
void error(String message);
57-
void end();
76+
void start();
77+
78+
void error(String message);
79+
80+
void end();
5881
```
5982
The second purpose of a Tracer is to allow tracing across process boundaries. To achieve that these kind of traces supply so called tags. Tags are strings or byte arrays that enable Dynatrace to trace a transaction end to end. As such the tag is the one information that you need to transport across these calls yourselfs.
6083

@@ -66,33 +89,33 @@ You can use the SDK to trace proprietary IPC communication from one process to t
6689
To trace any kind of remote call you first need to create a Tracer. The Tracer object represents the endpoint that you want to call, as such you need to supply the name of the remote service and remote method. In addition you need to transport the tag in your remote call to the server side if you want to trace it end to end.
6790

6891
```Java
69-
OutgoingRemoteCallTracer outgoingRemoteCall = OneAgentSDK.traceOutgoingRemoteCall("remoteMethodToCall", "RemoteServiceName", "rmi://Endpoint/service", ChannelType.TCP_IP, "remoteHost:1234");
70-
outgoingRemoteCall.setProtocolName("RMI/custom");
71-
outgoingRemoteCall.start();
72-
try {
73-
String tag = outgoingRemoteCall.getDynatraceStringTag();
74-
// make the call and transport the tag across to server
75-
} catch (Throwable e) {
76-
outgoingRemoteCall.error(e);
77-
} finally {
78-
outgoingRemoteCall.end();
79-
}
92+
OutgoingRemoteCallTracer outgoingRemoteCall = OneAgentSDK.traceOutgoingRemoteCall("remoteMethodToCall", "RemoteServiceName", "rmi://Endpoint/service", ChannelType.TCP_IP, "remoteHost:1234");
93+
outgoingRemoteCall.setProtocolName("RMI/custom");
94+
outgoingRemoteCall.start();
95+
try {
96+
String tag = outgoingRemoteCall.getDynatraceStringTag();
97+
// make the call and transport the tag across to server
98+
} catch (Throwable e) {
99+
outgoingRemoteCall.error(e);
100+
} finally {
101+
outgoingRemoteCall.end();
102+
}
80103
```
81104

82105
On the server side you need to wrap the handling and processing of your remote call as well. This will not only trace the server side call and everything that happens, it will also connect it to the calling side.
83106

84107
```Java
85-
IncomingRemoteCallTracer incomingRemoteCall = OneAgentSDK.traceIncomingRemoteCall("remoteMethodToCall", "RemoteServiceName", "rmi://Endpoint/service");
86-
incomingRemoteCall.setDynatraceStringTag(tag);
87-
incomingRemoteCall.start();
88-
try {
89-
incomingRemoteCall.setProtocolName("RMI/custom");
90-
doSomeWork(); // process the remoteCall
91-
} catch (Exception e) {
92-
incomingRemoteCall.error(e);
93-
}finally{
94-
incomingRemoteCall.end();
95-
}
108+
IncomingRemoteCallTracer incomingRemoteCall = OneAgentSDK.traceIncomingRemoteCall("remoteMethodToCall", "RemoteServiceName", "rmi://Endpoint/service");
109+
incomingRemoteCall.setDynatraceStringTag(tag);
110+
incomingRemoteCall.start();
111+
try {
112+
incomingRemoteCall.setProtocolName("RMI/custom");
113+
doSomeWork(); // process the remoteCall
114+
} catch (Exception e) {
115+
incomingRemoteCall.error(e);
116+
}finally{
117+
incomingRemoteCall.end();
118+
}
96119
```
97120

98121
### Compatibility OneAgent SDK for Java releases with OneAgent for Java releases

0 commit comments

Comments
 (0)