Skip to content

[Optional] Custom Span Tags

[Optional] Add custom span tags for additional info

  1. Custom span tags are already added for 3 of the functions. Let's take a look at how to add custom span tags in the 4th one, 'getFinancials'. Open up the 'getFinancials' Lambda function.
  2. Under line 2, add a new line and write from opentelemetry import trace. Under line 6, add with proper indentation

    customizedSpan = trace.get_current_span()
    customizedSpan.set_attribute("symbol", ticker)
    customizedSpan.set_attribute("finnhub.token", "brqivm7rh5rc4v2pmq8g")
    
    The final result should look like this:
    import json
    import requests
    from opentelemetry import trace
    
    def lambda_handler(event, context):
        ticker = event['symbol']
    
        customizedSpan = trace.get_current_span()
        customizedSpan.set_attribute("symbol", ticker)
        customizedSpan.set_attribute("finnhub.token", "brqivm7rh5rc4v2pmq8g")
    
    Source: Instrument your application code to add tags to spans

  3. Click Deploy to save your changes. Now if you run 'stockRanker' and look at the traces for 'getFinancials' in Splunk APM, you'll see that each span has tags for the stock symbol being analyzed and the API token being used. This can help with troubleshooting, in case of any errors.


Last update: August 31, 2022