Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions instana/singletons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import opentracing

from .agent import StandardAgent, AWSLambdaAgent
from .log import logger
from .tracer import InstanaTracer
from .recorder import StandardRecorder, AWSLambdaRecorder

Expand All @@ -18,15 +19,23 @@
span_recorder = StandardRecorder()


# Retrieve the globally configured agent
def get_agent():
"""
Retrieve the globally configured agent
@return: The Instana Agent singleton
"""
global agent
return agent


# Set the global agent for the Instana package. This is used for the
# test suite only currently.
def set_agent(new_agent):
"""
Set the global agent for the Instana package. This is used for the
test suite only currently.

@param new_agent: agent to replace current singleton
@return: None
"""
global agent
agent = new_agent

Expand All @@ -36,8 +45,11 @@ def set_agent(new_agent):
tracer = InstanaTracer(recorder=span_recorder)

if sys.version_info >= (3, 4):
from opentracing.scope_managers.asyncio import AsyncioScopeManager
async_tracer = InstanaTracer(scope_manager=AsyncioScopeManager(), recorder=span_recorder)
try:
from opentracing.scope_managers.asyncio import AsyncioScopeManager
async_tracer = InstanaTracer(scope_manager=AsyncioScopeManager(), recorder=span_recorder)
except Exception:
logger.debug("Error setting up async_tracer:", exc_info=True)


# Mock the tornado tracer until tornado is detected and instrumented first
Expand All @@ -54,14 +66,21 @@ def setup_tornado_tracer():
opentracing.tracer = tracer


# Retrieve the globally configured tracer
def get_tracer():
"""
Retrieve the globally configured tracer
@return: Tracer
"""
global tracer
return tracer


# Set the global tracer for the Instana package. This is used for the
# test suite only currently.
def set_tracer(new_tracer):
"""
Set the global tracer for the Instana package. This is used for the
test suite only currently.
@param new_tracer: The new tracer to replace the singleton
@return: None
"""
global tracer
tracer = new_tracer