Beispiel #1
0
    def _enable_otel(self):

        from opentelemetry                  import trace
        from opentelemetry.propagate        import set_global_textmap
        from opentelemetry.sdk.resources    import Resource
        from opentelemetry.sdk.trace        import TracerProvider
        from opentelemetry.exporter.datadog import DatadogSpanExporter, DatadogExportSpanProcessor
        from opentelemetry.exporter.datadog.propagator import DatadogFormat
        from opentelemetry.instrumentation.grpc import GrpcInstrumentorClient

        r = Resource({
            'app.version':      __version__,
            'app.framework':    ':'.join((self._name, __version__)),
            'net.hostname':     socket.gethostname(),
            'service.name':     self._name,
            'service.version':  __version__,
        })
        trace.set_tracer_provider(TracerProvider(resource = r))
        self.tracer = trace.get_tracer_provider()

        self.exporter = DatadogSpanExporter(
            service   = self._name,
            agent_url = 'http://localhost:8126',
            version   = __version__,
            env       = 'dev',
        )
        self.tracer.add_span_processor(DatadogExportSpanProcessor(self.exporter))
        set_global_textmap(DatadogFormat())


        # setup client instrumentation
        GrpcInstrumentorClient().instrument(tracer = self.tracer)
        BotocoreInstrumentor().instrument(tracer_provider = self.tracer)
        BotoInstrumentor().instrument(tracer_provider = self.tracer)
Beispiel #2
0
    def __init__(self, app, service='atlas-api', sqlalchemy_engine=None, datadog_agent=None,
                 span_callback=None, ignored_paths: List[str] = None, sql_service=None):
        self.app = app
        trace.set_tracer_provider(TracerProvider())
        self.tracer = trace.get_tracer(__name__)
        if datadog_agent:
            from ddtrace.internal.writer import AgentWriter
            from opentelemetry.exporter.datadog import DatadogExportSpanProcessor, \
                DatadogSpanExporter
            exporter = DatadogSpanExporter(agent_url=datadog_agent, service=service)
            exporter._agent_writer = AgentWriter(datadog_agent)
            span_processor = DatadogExportSpanProcessor(exporter)
            trace.get_tracer_provider().add_span_processor(span_processor)

        AtlasFastAPIInstrumentor.instrument_app(app, span_callback=span_callback,
                                                ignored_paths=ignored_paths)
        RequestsInstrumentor().instrument()
        BotocoreInstrumentor().instrument(tracer_provider=trace.get_tracer_provider())
        BotoInstrumentor().instrument(tracer_provider=trace.get_tracer_provider())
        RedisInstrumentor().instrument(tracer_provider=trace.get_tracer_provider())
        if sqlalchemy_engine:
            sqlalch_service_name = service if not sql_service else sql_service
            SQLAlchemyInstrumentor().instrument(engine=sqlalchemy_engine,
                                                service=sqlalch_service_name)
Beispiel #3
0
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from opentelemetry import trace
from opentelemetry.exporter.datadog import (
    DatadogExportSpanProcessor,
    DatadogSpanExporter,
)
from opentelemetry.sdk.trace import TracerProvider

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

exporter = DatadogSpanExporter(agent_url="http://localhost:8126",
                               service="example")

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

with tracer.start_as_current_span("foo"):
    with tracer.start_as_current_span("bar"):
        with tracer.start_as_current_span("baz"):
            print("Hello world from OpenTelemetry Python!")
Beispiel #4
0
    DatadogSpanExporter,
)
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider

app = Flask(__name__)
FlaskInstrumentor().instrument_app(app)
RequestsInstrumentor().instrument()


trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
    DatadogExportSpanProcessor(
        DatadogSpanExporter(
            agent_url="http://127.0.0.1:8126/", service="dd_tracing_example"
        )
    )
)
tracer = trace.get_tracer(__name__)

with tracer.start_as_current_span("span_1"):
    with tracer.start_as_current_span("span_2"):
        with tracer.start_as_current_span("span_3"):
            print("Hello world from {{cookiecutter.app_name}}!")


def create_app(config_object="{{cookiecutter.app_name}}.settings"):
    """Create application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/.

    :param config_object: The configuration object to use.
Beispiel #5
0
    DatadogExportSpanProcessor,
    DatadogSpanExporter,
)
from opentelemetry.propagate import inject
from opentelemetry.sdk import resources
from opentelemetry.sdk.trace import TracerProvider

service_name = "example-client"

resource = resources.Resource.create({"service.name": service_name})

trace.set_tracer_provider(TracerProvider(resource=resource))

trace.get_tracer_provider().add_span_processor(
    DatadogExportSpanProcessor(
        DatadogSpanExporter(agent_url="http://localhost:8126",
                            service=service_name)))

tracer = trace.get_tracer(__name__)

assert len(argv) == 2

with tracer.start_as_current_span("client"):

    with tracer.start_as_current_span("client-server"):
        headers = {}
        inject(headers)
        requested = get(
            "http://localhost:8082/server_request",
            params={"param": argv[1]},
            headers=headers,
Beispiel #6
0
from opentelemetry.propagators.composite import CompositeHTTPPropagator
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.resources import Resource

import os

service_name = os.getenv('DD_SERVICE')
dd_agent = os.getenv('DD_AGENT_HOST')
app = Sanic(name=service_name)

resource = Resource.create({"service.name": service_name})
trace.set_tracer_provider(TracerProvider(resource=resource))

trace.get_tracer_provider().add_span_processor(
    DatadogExportSpanProcessor(
        DatadogSpanExporter(agent_url="http://" + dd_agent + ":8126",
                            service=service_name)))

global_textmap = get_global_textmap()
if isinstance(global_textmap, CompositeHTTPPropagator) and not any(
        isinstance(p, DatadogFormat) for p in global_textmap._propagators):
    set_global_textmap(
        CompositeHTTPPropagator(global_textmap._propagators +
                                [DatadogFormat()]))
else:
    set_global_textmap(DatadogFormat())

tracer = trace.get_tracer(__name__)


@app.route('/')
Beispiel #7
0
    DatadogExportSpanProcessor,
    DatadogSpanExporter,
)
from opentelemetry.exporter.datadog.propagator import DatadogFormat
from opentelemetry.propagate import get_global_textmap, set_global_textmap
from opentelemetry.propagators.composite import CompositePropagator
from opentelemetry.sdk.trace import TracerProvider

app = Flask(__name__)

trace.set_tracer_provider(TracerProvider())

trace.get_tracer_provider().add_span_processor(
    DatadogExportSpanProcessor(
        DatadogSpanExporter(
            agent_url="http://localhost:8126", service="example-server"
        )
    )
)

# append Datadog format for propagation to and from Datadog instrumented services
global_textmap = get_global_textmap()
if isinstance(global_textmap, CompositePropagator) and not any(
    isinstance(p, DatadogFormat) for p in global_textmap._propagators
):
    set_global_textmap(
        CompositePropagator(global_textmap._propagators + [DatadogFormat()])
    )
else:
    set_global_textmap(DatadogFormat())