0

i have a simple python application without any framework and API calls. how i will monitor python application on instana kubernates. i want code snippet to add with python application ,which trace application and display on instana

1 Answers1

2

how i will monitor python application on instana kubernates

There is publicly available guide, that should help you setting up the kubernetes agent.

i have a simple python application without any framework and API calls

Well, instana is for distributed tracing, meaning distributed components calling each other, each other's APIs predominantly by using known frameworks (with registered spans).

Nevertheless, you could make use of SDKSpan, here is a super simple example:

import os
os.environ["INSTANA_TEST"] = "true"
import instana

import opentracing.ext.tags as ext
from instana.singletons import get_tracer
from instana.util.traceutils import get_active_tracer

def foo():
    tracer = get_active_tracer()
    with tracer.start_active_span(
            operation_name="foo_op",
            child_of=tracer.active_span
            ) as foo_scope:
        foo_scope.span.set_tag(ext.SPAN_KIND, "exit")

        result = 20 + 1
        foo_scope.span.set_tag("result", result)
        return result

def main():
    tracer = get_tracer()
    with tracer.start_active_span(operation_name="main_op") as main_scope:
        main_scope.span.set_tag(ext.SPAN_KIND, "entry")
        answer = foo() + 21
        main_scope.span.set_tag("answer", answer)

if __name__ == '__main__':
    main()

spans = get_tracer().recorder.queued_spans()
print('\nRecorded Spans and their IDs:',
      *[(index,
         span.s,
         span.data['sdk']['name'],
         dict(span.data['sdk']['custom']['tags']),
         ) for index, span in enumerate(spans)],
      sep='\n')

This should work in any environment, even without an agent and should give you an output like this:

Recorded Spans and their IDs:
(0, 'ab3af60079f3ca57', 'foo_op', {'span.kind': 'exit', 'result': 21})
(1, '53b67f7298684cb7', 'main_op', {'span.kind': 'entry', 'answer': 42})

Of course in a production, you wouldn't want to print the recorded spans, but send it to the well configured agent, so you should remove setting the INSTANA_TEST.

Ferenc Géczi
  • 563
  • 3
  • 6