Giter Club home page Giter Club logo

Comments (2)

dm03514 avatar dm03514 commented on May 26, 2024

Would it be possible to support opentracing inject/extract API for this case? Which could look like:

from thundra.thundra_agent import Thundra

thundra = Thundra()

@thundra
def handler(event, context):
    tracer = ThundraTracer.get_instance()
    result = {'message': 'hello'} 
    tracer.inject(
       tracer.scope_manager.active(), // <- not sure of the API call to get the active span
       opentracing.Format.TEXT_MAP,
       result,
    )
    return result

Then the invoked lambda, either explicitly calls extract or the thundra tracer agent inspects the payload?

from thundra.thundra_agent import Thundra

thundra = Thundra()

@thundra
def handler(event, context):
    tracer = ThundraTracer.get_instance()
    span_context = tracer.extract(
      format=opentracing.Format.TEXT_MAP,
      carrier=context, 
    )
    with tracer.start_active_span(operation_name="write_user_to_db", childOf=span_context) as scope:
        # perform operation
    print('received: {} {}'.format(event, context))
    return {'hi': 'hi'}

What do you think?

from thundra-agent-python.

default-usr avatar default-usr commented on May 26, 2024

Hello, add_outgoing_trace_link and add_incoming_trace_link functions can be used to connect the async lambda, you can use an identifier for the trace as a trace link and add it into your response and use it in the invoked lambda. (To use this functions as below, thundra agent version should be >= 2.5.10 and layer >=48)

Lambda 1

import uuid
import thundra

def lambda_handler(event, context):
    
    # use any trace identifier here
    trace_link = str(uuid.uuid4())
    thundra.add_outgoing_trace_link(trace_link)
    return {
        'message': 'hello',
        'thundra_trace_link': trace_link
    }

Lambda 2

import thundra

def lambda_handler(event, context):
    
    thundra_trace_link = event.get("responsePayload", {}).get("thundra_trace_link")
    if thundra_trace_link is not None:
        thundra.add_incoming_trace_link(thundra_trace_link)

from thundra-agent-python.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.