예제 #1
0
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor

import os
from datetime import datetime, timedelta
from sqlalchemy import create_engine
import urllib

from .business_layer_adls import BusinessLayer

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

instrumentation_key = os.environ["APPINSIGHTS_INSTRUMENTATIONKEY"]

# SpanExporter receives the spans and send them to the target location
exporter = AzureMonitorSpanExporter(connection_string='InstrumentationKey=' +
                                    instrumentation_key, )

span_processor = BatchExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

# connection_string = os.environ["SQL_CONNECTION_STRING"]

# params = urllib.parse.quote_plus(
#     connection_string)  # urllib.parse.quote_plus for python 3

# conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params)
# engine = create_engine(conn_str, echo=True)

# SQLAlchemyInstrumentor().instrument(
#     engine=engine,
#     service="GenerateTimeSeriesData",
예제 #2
0
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

from azure_monitor import AzureMonitorSpanExporter


# Callback function to add os_type: linux to span properties
def callback_function(envelope):
    envelope.data.base_data.properties["os_type"] = "linux"
    return True


exporter = AzureMonitorSpanExporter(
    connection_string="InstrumentationKey=<INSTRUMENTATION KEY HERE>")
exporter.add_telemetry_processor(callback_function)

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
span_processor = BatchExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

with tracer.start_as_current_span("hello"):
    print("Hello, World!")

input("Press any key to exit...")
예제 #3
0
from opentelemetry.sdk.metrics import Counter, MeterProvider
from opentelemetry.sdk.metrics.export.controller import PushController
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from opentelemetry.ext.requests import RequestsInstrumentor
import time
import random
import socket
import os
import requests

# Setup distributed tracing
trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

trace_exporter = AzureMonitorSpanExporter(
    instrumentation_key=os.environ['APPINSIGHTS_INSTRUMENTATION_KEY'])

span_processor = BatchExportSpanProcessor(trace_exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

RequestsInstrumentor().instrument()

# Setup metrics
metrics_exporter = AzureMonitorMetricsExporter(
    instrumentation_key=os.environ['APPINSIGHTS_INSTRUMENTATION_KEY'])
metrics.set_meter_provider(MeterProvider())
meter = metrics.get_meter(__name__)
PushController(meter, metrics_exporter, 10)

tfgen_counter = meter.create_metric(
    name="tfgen_counter",
예제 #4
0
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from azure_monitor import AzureMonitorSpanExporter
from opentelemetry import trace
from opentelemetry.sdk.trace import Tracer
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

trace.set_preferred_tracer_implementation(lambda T: Tracer())
tracer = trace.tracer()
tracer.add_span_processor(SimpleExportSpanProcessor(
    AzureMonitorSpanExporter()))

with tracer.start_as_current_span("hello") as span:
    print("Hello, World!")
예제 #5
0
import requests
from opentelemetry import trace
from opentelemetry.ext.flask import FlaskInstrumentor
from opentelemetry.ext.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

import flask
from azure_monitor import AzureMonitorSpanExporter

# The preferred tracer implementation must be set, as the opentelemetry-api
# defines the interface with a no-op implementation.
trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

exporter = AzureMonitorSpanExporter(
    connection_string="InstrumentationKey=<INSTRUMENTATION KEY HERE>")

# SpanExporter receives the spans and send them to the target location.
span_processor = BatchExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

# Integrations are the glue that binds the OpenTelemetry API and the
# frameworks and libraries that are used together, automatically creating
# Spans and propagating context as appropriate.

# Enable instrumentation in the requests library.
RequestsInstrumentor().instrument()

app = flask.Flask(__name__)
# Enable instrumentation in the flask library.
FlaskInstrumentor().instrument_app(app)
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from azure_monitor import AzureMonitorSpanExporter
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerSource
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor

trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
span_processor = SimpleExportSpanProcessor(
    AzureMonitorSpanExporter(instrumentation_key="<INSTRUMENTATION KEY HERE>")
)
trace.tracer_source().add_span_processor(span_processor)
tracer = trace.tracer_source().get_tracer(__name__)

with tracer.start_as_current_span("hello") as span:
    print("Hello, World!")
예제 #7
0
        'POD_NAMESPACE')
    envelope.data.base_data.properties['kube_cpu_limit'] = os.getenv(
        'CPU_LIMIT')
    envelope.data.base_data.properties['kube_memory_limit'] = os.getenv(
        'MEMORY_LIMIT')
    # Read labels
    f = open("/podinfo/labels")
    for line in f:
        key, value = line.partition("=")[::2]
        envelope.data.base_data.properties['labels.%s' % key] = value.replace(
            '"', '')
    return True


# Add Azure Monitor exporter
exporterAzure = AzureMonitorSpanExporter(
    connection_string=appInsightsConnectionString)
exporterAzure.add_telemetry_processor(azure_monitor_metadata)
trace.get_tracer_provider().add_span_processor(
    SimpleExportSpanProcessor(exporterAzure))

# Create Flask object
app = flask.Flask(__name__)

# Add automatic instrumentation
RequestsInstrumentor().instrument()
FlaskInstrumentor().instrument_app(app)
PyMySQLInstrumentor().instrument()

# Prepare database
conn = pymysql.connect(host=mySqlHost,
                       user=mySqlUsername,
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import requests

from azure_monitor import AzureMonitorSpanExporter
from opentelemetry import trace
from opentelemetry.ext import http_requests
from opentelemetry.sdk.trace import Tracer
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

trace.set_preferred_tracer_implementation(lambda T: Tracer())
tracer = trace.tracer()
http_requests.enable(tracer)
span_processor = BatchExportSpanProcessor(AzureMonitorSpanExporter())
tracer.add_span_processor(span_processor)

response = requests.get(url="http://127.0.0.1:5000/")
span_processor.shutdown()