def main(): call_msg = [] def diag_cb(msg): sys.stderr.flush() call_msg.append(msg) sdk = onesdk.SDK.get() try: sdk.set_diagnostic_callback(diag_cb) sdk.create_database_info(None, None, onesdk.Channel(0)) gc.collect() gc.collect() gc.collect() print(call_msg) n_msgs = len(call_msg) # Database name must not be null (from CSDK), leaked db info handle assert n_msgs == 2 assert all(isinstance(m, six.text_type) for m in call_msg) sdk.set_diagnostic_callback(None) sdk.create_database_info(None, None, onesdk.Channel(0)) print(call_msg[n_msgs:]) assert len(call_msg) == n_msgs finally: oneagent.shutdown()
async def shutdown(): # リクエストを受けないようにする(readinessを落とすなど) logging.info('Change status for maintenance.') # すべてのリクエストが完了するまで待つ logging.info('Wait to complete requests.') await asyncio.sleep(1) # リソースの解放などの終了処理を実行する logging.info('Release resources.') oneagent.shutdown() tornado.ioloop.IOLoop.current().stop()
def main(): args = return_args() # args specified in configure_arg_parser() function config_file = args.config_file all_set, sdk = get_sdk() # returns a boolean if init went well and the sdk if successful if all_set: config = get_config(config_file) # access value like: config["webRequests"][0]["url"] print("Beginning traffic simulation...") completed_counter = 0 # used in loop while completed_counter < len(config[WEB_REQUESTS]): simulate_requests(config[WEB_REQUESTS][completed_counter][URL], config[WEB_REQUESTS][completed_counter][METHOD], config[WEB_REQUESTS][completed_counter][COUNT], sdk) completed_counter += 1 print("Done. Cooling down...") time.sleep(COOL_DOWN_PERIOD) print("Shutting down...") oneagent.shutdown()
def test_load_old_agent(): saved_path = os.environ.get('DT_AGENTLIBRARY', '') try: assert os.environ['DT_OLDAGENTLIBRARY'] is not None assert os.environ['DT_OLDAGENTLIBRARY'] != '' os.environ['DT_AGENTLIBRARY'] = os.environ.get('DT_OLDAGENTLIBRARY', '') sdk_options = oneagent.sdkopts_from_commandline(remove=True) init_result = oneagent.initialize(sdk_options) assert init_result.error is not None assert init_result.status == InitResult.STATUS_INIT_ERROR sdk = oneagent.get_sdk() assert sdk.agent_state == AgentState.NOT_INITIALIZED assert sdk.agent_found assert not sdk.agent_is_compatible assert sdk.agent_version_string == '1.141.246.20180604-140607/' + shipped_c_stub_version finally: oneagent.shutdown() os.environ['DT_AGENTLIBRARY'] = saved_path
def main(): # This gathers arguments prefixed with '--dt_' from sys.argv into the # returned list. See also the basic-sdk-sample. sdk_options = oneagent.sdkopts_from_commandline(remove=True) # Before using the SDK you have to initialize the OneAgent. In this scenario, we # initialize the SDK and prepare it for forking. # # Passing in the sdk_options is entirely optional and usually not required # as all settings will be automatically provided by the Dynatrace OneAgent # that is installed on the host. # # To activate the forking support add the optional 'forkable' parameter and set it to True. # # If you run this example on Windows then you'll get an "Invalid Argument" error back # because there's no forking support for Windows available. init_result = oneagent.initialize(sdk_options, forkable=True) try: if init_result.error is not None: print('Error during SDK initialization:', init_result.error) # While not by much, it is a bit faster to cache the result of # oneagent.get_sdk() instead of calling the function multiple times. sdk = getsdk() # The agent state is one of the integers in oneagent.sdk.AgentState. # Since we're using the 'forkable' mode the state will be TEMPORARILY_INACTIVE (1) on Linux. print('Agent state (parent process):', sdk.agent_state) # In the parent, the state will be PARENT_INITIALIZED (1). print('Agent fork state (parent process):', sdk.agent_fork_state) # The instance attribute 'agent_found' indicates whether an agent could be found or not. print('Agent found:', sdk.agent_found) # If an agent was found but it is incompatible with this version of the SDK for Python # then 'agent_is_compatible' would be set to false. print('Agent is compatible:', sdk.agent_is_compatible) # The agent version is a string holding both the OneAgent version and the # OneAgent SDK for C/C++ version separated by a '/'. print('Agent version:', sdk.agent_version_string) if init_result.error is None: fork_children() input('Now wait until the path appears in the UI ...') finally: shutdown_error = oneagent.shutdown() if shutdown_error: print('Error shutting down SDK:', shutdown_error)
def main(): print('+main') oneagent.logger.setLevel(1) oneagent.logger.addHandler(logging.StreamHandler()) # This gathers arguments prefixed with '--dt_' from sys.argv into the # returned list. See try_init below. sdk_options = oneagent.sdkopts_from_commandline(remove=True) # If you do not call try_init() manually, the first call to # oneagent.sdk.SDK.get() will attempt to initialize the SDK with default # options, swallowing any errors, which is why manually calling try_init() # is recommended. # Passing in the sdk_options is entirely optional and usually not required # as all settings will be automatically provided by the Dynatrace OneAgent # that is installed on the host. init_result = oneagent.try_init(sdk_options) try: if init_result.error is not None: print('Error during SDK initialization:', init_result.error) # While not by much, it is a bit faster to cache the result of # oneagent.sdk.SDK.get() instead of calling the function multiple times. sdk = getsdk() # The agent state is one of the integers in oneagent.sdk.AgentState. print('Agent state:', sdk.agent_state) # The agent version is the version of the installed OneAgent, not the # version of the SDK. print('Agent version:', sdk.agent_version_string) mock_incoming_web_request() # We use trace_incoming_remote_call here, because it is one of the few # calls that create a new path if none is running yet. with sdk.trace_incoming_remote_call('main', 'main', 'main'): # Simulate some remote calls outgoing_remote_call(success=True) outgoing_remote_call(success=True) outgoing_remote_call(success=False) print('-main') input('Now wait until the path appears in the UI...') finally: shutdown_error = oneagent.shutdown() if shutdown_error: print('Error shutting down SDK:', shutdown_error)
'PRODUCT_CATALOG_SERVICE_ADDR environment variable not set') logger.info("product catalog address: " + catalog_addr) channel = grpc.insecure_channel(catalog_addr) product_catalog_stub = demo_pb2_grpc.ProductCatalogServiceStub(channel) # create gRPC server server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), interceptors=(tracer_interceptor, )) # add class to gRPC server service = RecommendationService() demo_pb2_grpc.add_RecommendationServiceServicer_to_server(service, server) health_pb2_grpc.add_HealthServicer_to_server(service, server) #init oneagent if not oneagent.initialize(['loglevelsdk=finest', 'loglevel=finest']): print('Error initializing OneAgent SDK.') # start server logger.info("listening on port: " + port) server.add_insecure_port('[::]:' + port) server.start() # keep alive try: while True: time.sleep(10000) except KeyboardInterrupt: server.stop(0) oneagent.shutdown()
def shutdown(): oneagent.shutdown()
def main(): print('+main') # This gathers arguments prefixed with '--dt_' from sys.argv into the # returned list. See initialize below. sdk_options = oneagent.sdkopts_from_commandline(remove=True) # Before using the SDK you have to initialize the OneAgent. You can call oneagent.initialize() # as often as you want, but you also have to call oneagent.shutdown() for every call to # initialize() as well. # # Passing in the sdk_options is entirely optional and usually not required # as all settings will be automatically provided by the Dynatrace OneAgent # that is installed on the host. init_result = oneagent.initialize(sdk_options) try: if init_result.error is not None: print('Error during SDK initialization:', init_result.error) # While not by much, it is a bit faster to cache the result of # oneagent.get_sdk() instead of calling the function multiple times. sdk = getsdk() # Set the diagnostic callback. Strongly recommended. sdk.set_diagnostic_callback(_diag_callback) # Set the verbose callback. # Not recommended in production as lots of messages can be emitted. if IN_DEV_ENVIRONMENT: sdk.set_verbose_callback(_diag_callback) # The agent state is one of the integers in oneagent.sdk.AgentState. print('Agent state:', sdk.agent_state) # The instance attribute 'agent_found' indicates whether an agent could be found or not. print('Agent found:', sdk.agent_found) # If an agent was found but it is incompatible with this version of the SDK for Python # then 'agent_is_compatible' would be set to false. print('Agent is compatible:', sdk.agent_is_compatible) # The agent version is a string holding both the OneAgent version and the # OneAgent SDK for C/C++ version separated by a '/'. print('Agent version:', sdk.agent_version_string) mock_incoming_web_request() mock_outgoing_web_request() mock_outgoing_message() mock_custom_service() # We use trace_incoming_remote_call here, because it is one of the few # calls that create a new path if none is running yet. with sdk.trace_incoming_remote_call('main', 'main', 'main'): # We want to start an asynchronous execution at this time, so we create an # in-process link which we will use afterwards (or in a different thread). link = sdk.create_in_process_link() # Simulate some remote calls outgoing_remote_call(success=True) outgoing_remote_call(success=True) outgoing_remote_call(success=False) # Now the asynchronous execution starts. So we create an in-process tracer. We're using # the in-process link which we've created above. This link specifies where the traced # actions below will show up in the path. with sdk.trace_in_process_link(link): outgoing_remote_call(success=True) print('-main') input('Now wait until the path appears in the UI...') finally: shutdown_error = oneagent.shutdown() if shutdown_error: print('Error shutting down SDK:', shutdown_error)
session_token=credentials.token) elasticsearchclient = Elasticsearch( hosts=[{ 'host': ELASTICSEARCH_HOST, 'port': 443 }], http_auth=awsauth, use_ssl=True, verify_certs=True, connection_class=RequestsHttpConnection) sdk.add_custom_request_attribute('project', 's3workflow') sdk.add_custom_request_attribute('Container', 'rekognitioncontainer') while True: with sdk.trace_custom_service('get_message()', 'SQS'): message = get_message(sqs_client, REKOGNITION_QUEUE) with sdk.trace_custom_service('detect_text()', 'REKOGNITION'): detect_text_response = detect_text(rekognition_client, message) message['detect_text_response'] = detect_text_response with sdk.trace_custom_service('send_message()', 'SQS'): send_message(sqs_client, message, COMPREHEND_QUEUE) with sdk.trace_custom_service('put_document()', 'ELASTICSEARCH'): put_document(elasticsearchclient, message) finally: shutdown_error = oneagent.shutdown() if shutdown_error: print('Error shutting down SDK:', shutdown_error)
def sdk_shutdown(): ''' Shut Down the OneAgent Python SDK ''' shutdown_error = oneagent.shutdown() if shutdown_error: print('Error shutting down SDK:', shutdown_error, file=sys.stderr)