@@ -20,6 +20,10 @@ This SDK enables Dynatrace customers to extend request level visibility into Pyt
2020 * [ Outgoing web requests] ( #outgoing-web-requests )
2121 * [ Trace in-process asynchronous execution] ( #trace-in-process-asynchronous-execution )
2222 * [ Custom request attributes] ( #custom-request-attributes )
23+ * [ Custom services] ( #custom-services )
24+ * [ Messaging] ( #messaging )
25+ * [ Outgoing Messages] ( #outgoing-messaging )
26+ * [ Incoming Messages] ( #incoming-messaging )
2327- [ Troubleshooting] ( #troubleshooting )
2428 * [ Installation issues] ( #installation-issues )
2529 * [ Post-installation issues] ( #post-installation-issues )
@@ -54,6 +58,7 @@ Dynatrace OneAgent version (it is the same as
5458| :----------------------| :---------------------| :-----------------|
5559| 1.0 | 1.1.0 | ≥1.141 |
5660| 1.1 | 1.3.1 | ≥1.151 |
61+ | 1.2 | 1.4.1 | ≥1.161 |
5762
5863<a name =" #using-the-oneagent-sdk-for-python-in-your-application " ></a >
5964## Using the OneAgent SDK for Python in your application
@@ -207,6 +212,8 @@ A more detailed specification of the features can be found in [Dynatrace OneAgen
207212| Outgoing web requests | ≥1.1.0 |
208213| Custom request attributes | ≥1.1.0 |
209214| In-process linking | ≥1.1.0 |
215+ | Messaging | ≥1.2.0 |
216+ | Custom services | ≥1.2.0 |
210217
211218<a name =" remote-calls " ></a >
212219### Remote calls
@@ -387,7 +394,7 @@ The provided in-process link must not be serialized and can only be used inside
387394tracing where the asynchronous execution takes place:
388395
389396``` python
390- with sdk.trace_in_process_link(in_process_link):
397+ with sdk.trace_in_process_link(in_process_link):
391398 # Do the asynchronous job
392399 :
393400```
@@ -411,6 +418,121 @@ Check out the documentation at:
411418* [ ` add_custom_request_attribute ` ] ( https://dynatrace.github.io/OneAgent-SDK-for-Python/docs/sdkref.html#oneagent.sdk.SDK.add_custom_request_attribute )
412419
413420
421+ <a name =" custom-services " ></a >
422+ ### Custom services
423+ You can use the SDK to trace custom service methods. A custom service method is a meaningful part
424+ of your code that you want to trace but that does not fit any other tracer. An example could be
425+ the callback of a periodic timer.
426+
427+ ``` python
428+ with sdk.trace_custom_service(' onTimer' , ' CleanupTask' ):
429+ # Do the cleanup task
430+ :
431+ ```
432+
433+ Check out the documentation at:
434+ * [ ` trace_custom_service ` ] ( https://dynatrace.github.io/OneAgent-SDK-for-Python/docs/sdkref.html#oneagent.sdk.SDK.trace_custom_service )
435+
436+
437+ <a name =" messaging " ></a >
438+ ### Messaging
439+
440+ You can use the SDK to trace messages sent or received via a messaging system. When tracing messages,
441+ we distinguish between:
442+
443+ * sending a message
444+ * waiting for and receiving a message
445+ * processing a received message
446+
447+ <a name =" outgoing-messaging " ></a >
448+ #### Outgoing Messages
449+
450+ All messaging related tracers need a messaging system info object which you have to create prior
451+ to the respective messaging tracer, which is an outgoing message tracer in the example below.
452+
453+ ``` python
454+ msi_handle = sdk.create_messaging_system_info(
455+ ' myMessagingSystem' , ' requestQueue' , MessagingDestinationType.QUEUE ,
456+ ChannelType.TCP_IP , ' 10.11.12.13' )
457+
458+ with msi_handle:
459+ with sdk.trace_outgoing_message(msi_handle) as tracer:
460+ # Get and set the Dynatrace tag.
461+ tag = tracer.outgoing_dynatrace_string_tag
462+ message_to_send.add_header_field(oneagent.sdk.DYNATRACE_MESSAGE_PROPERTY_NAME , tag)
463+
464+ # Send the message.
465+ the_queue.send(message_to_send)
466+
467+ # Optionally set message and/or correlation IDs
468+ tracer.set_vendor_message_id(message_to_send.get_message_id())
469+ tracer.set_correlation_id(message_to_send.get_correlation_id())
470+ ```
471+
472+ <a name =" incoming-messaging " ></a >
473+ #### Incoming Messages
474+
475+ On the incoming side, we need to differentiate between the blocking receiving part and processing
476+ the received message. Therefore two different tracers are being used:
477+
478+ * IncomingMessageReceiveTracer
479+ * IncomingMessageProcessTracer
480+
481+ ``` python
482+ msi_handle = sdk.create_messaging_system_info(
483+ ' myMessagingSystem' , ' requestQueue' , MessagingDestinationType.QUEUE ,
484+ ChannelType.TCP_IP , ' 10.11.12.13' )
485+
486+ with msi_handle:
487+ # Create the receive tracer for incoming messages.
488+ with sdk.trace_incoming_message_receive(msi_handle):
489+ # This is a blocking call, which will return as soon as a message is available.
490+ Message query_message = the_queue.receive()
491+
492+ # Get the Dynatrace tag from the message.
493+ tag = query_message.get_header_field(oneagent.sdk.DYNATRACE_MESSAGE_PROPERTY_NAME )
494+
495+ # Create the tracer for processing incoming messages.
496+ tracer = sdk.trace_incoming_message_process(msi_handle, str_tag = tag)
497+ tracer.set_vendor_message_id(query_message.get_vendor_id())
498+ tracer.set_correlation_id(query_message.get_correlation_id())
499+
500+ with tracer:
501+ # Now let's handle the message ...
502+ print (' handle incoming message' )
503+ ```
504+
505+ In case of non-blocking receive (e. g. using an event handler), there is no need to use an
506+ IncomingMessageReceiveTracer - just trace processing of the message by using the IncomingMessageProcessTracer:
507+
508+ ``` python
509+ msi_handle = sdk.create_messaging_system_info(
510+ ' myMessagingSystem' , ' requestQueue' , MessagingDestinationType.QUEUE ,
511+ ChannelType.TCP_IP , ' 10.11.12.13' )
512+
513+ def on_message_received (message ):
514+ # Get the Dynatrace tag from the message.
515+ tag = message.get_header_field(oneagent.sdk.DYNATRACE_MESSAGE_PROPERTY_NAME )
516+
517+ # Create the tracer for processing incoming messages.
518+ tracer = sdk.trace_incoming_message_process(msi_handle, str_tag = tag)
519+ tracer.set_vendor_message_id(message.get_vendor_id())
520+ tracer.set_correlation_id(message.get_correlation_id())
521+
522+ with tracer:
523+ # Now let's handle the message ...
524+ print (' handle incoming message' )
525+ ```
526+
527+ See the documentation for more information:
528+
529+ * [ ` create_messaging_system_info ` ] ( https://dynatrace.github.io/OneAgent-SDK-for-Python/docs/sdkref.html#oneagent.sdk.SDK.create_messaging_system_info )
530+ * [ ` trace_outgoing_message ` ] ( https://dynatrace.github.io/OneAgent-SDK-for-Python/docs/sdkref.html#oneagent.sdk.tracers.trace_outgoing_message )
531+ * [ ` trace_incoming_message_receive ` ] ( https://dynatrace.github.io/OneAgent-SDK-for-Python/docs/sdkref.html#oneagent.sdk.tracers.trace_incoming_message_receive )
532+ * [ ` trace_incoming_message_process ` ] ( https://dynatrace.github.io/OneAgent-SDK-for-Python/docs/sdkref.html#oneagent.sdk.tracers.trace_incoming_message_process )
533+ * [ General information on tagging] ( https://dynatrace.github.io/OneAgent-SDK-for-Python/docs/tagging.html )
534+
535+
414536<a name =" troubleshooting " ></a >
415537## Troubleshooting
416538
0 commit comments