serverless / dashboard

MIT License
26 stars 10 forks source link

Fix botocore instrumentation #841

Closed selcukcihan closed 1 year ago

selcukcihan commented 1 year ago

Description

Testing done

import os

# Slack bolt
from slack_bolt import App
from slack_bolt.adapter.aws_lambda import SlackRequestHandler

# Set up the bolt application
app = App(
    process_before_response = True,
    token = os.environ['SLACK_BOT_TOKEN'],
    signing_secret = os.environ['SLACK_SIGNING_SECRET']
)

# Acknowledge incoming slack command
def acknowledge_command(body, ack):
    # Acknowledge command
    if (body_text := body.get('text')) is None or body_text.strip() == '':
        ack(f':x: `{body.get("command")}` needs more context')

    # Got command, no response
    ack()

# Actual processing of the command
def process_command(respond, body):
    respond(f'Completed! (task: {body.get("command")})')

# Register command with application
app.command('/test')(
    ack = acknowledge_command,
    lazy = [process_command]
)

# Set up lambda function
def handler(event, context):
    import json
    print(json.dumps(event))
    return SlackRequestHandler(app=app).handle(event, context)

serverless.yml

service: slack-bot

frameworkVersion: '3'

provider:
  name: aws
  runtime: python3.9
  architecture: arm64
  memorySize: 1024
  stage: dev
  region: us-east-1

  environment:
    SLS_SDK_DEBUG: "1"
    AWS_LAMBDA_EXEC_WRAPPER: "/opt/sls-sdk-python/exec_wrapper.py"
    SLS_ORG_ID: ${env:SLS_ORG_ID}
    SLS_DEV_MODE_ORG_ID: ${env:SLS_ORG_ID}
    SLS_DEV_TOKEN: ${env:SLS_DEV_TOKEN}
  layers:
    - arn:aws:lambda:us-east-1:692593327170:layer:sls-sdk-python:68
    - arn:aws:lambda:us-east-1:177335420605:layer:sls-external-extension-arm64-v0-6-4:1
  timeout: 30

  iam:
    role:
      statements:
        - Effect: Allow
          Action: 'lambda:InvokeFunction'
          Resource: '*'

functions:
  console:
    handler: console.handler
    url: true
    environment:
      SLACK_BOT_TOKEN: "YOUR-TOKEN-HERE"
      SLACK_SIGNING_SECRET: "YOUR-SECRET-HERE"

package:
  patterns:
    - '!node_modules/**'
    - '!.venv/**'

plugins:
  - serverless-python-requirements

Slack bot works fine

Screenshot 2023-07-17 at 11 53 57

selcukcihan commented 1 year ago

@Mmarzex I've created the PR that should fix https://linear.app/serverless/issue/SC-1250/duplicatetracespanname-error-in-python-sdk even though I haven't been able to reproduce it in a unit test.