我有一个简单的python应用程序,没有任何框架和API调用。如何监视instana kubernates上的python应用程序。我希望代码片段与python应用程序一起添加,该应用程序跟踪应用程序并在instana上显示。
发布于 2022-06-01 15:04:46
如何监视instana kubernates上的python应用程序
有公开可用的指南,这将帮助您设置库伯奈特斯剂。
我有一个简单的python应用程序,没有任何框架和API调用。
嗯,instana是用于分布式跟踪的,意思是分布式组件相互调用,彼此的API主要通过使用已知的框架(具有注册的跨)。
不过,您可以使用SDKSpan,下面是一个非常简单的示例:
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')这应该可以在任何环境中工作,即使没有代理,并且应该给出如下的输出:
Recorded Spans and their IDs:
(0, 'ab3af60079f3ca57', 'foo_op', {'span.kind': 'exit', 'result': 21})
(1, '53b67f7298684cb7', 'main_op', {'span.kind': 'entry', 'answer': 42})当然,在生产中,您不希望打印记录的跨度,而是将其发送到配置良好的代理,因此您应该删除对的设置
https://stackoverflow.com/questions/72451439
复制相似问题