如何解决OpenTelemetry自动插装与K8s应用中的Boto3冲突?
解决OpenTelemetry自动插装与应用Boto3版本冲突问题
当OpenTelemetry自动插装注入的opentelemetry-instrumentation-boto3依赖与应用自身的Boto3/Botocore版本不一致时,就会出现DEFAULT_CIPHERS导入失败这类依赖冲突问题,以下是几种可行的解决方法:
方法1:禁用Boto3的自动插装
直接在Instrumentation配置中排除Boto3的插装,避免依赖冲突。修改你的Instrumentation YAML文件,在python字段下添加disabled_instrumentations配置:
apiVersion: opentelemetry.io/v1alpha1 kind: Instrumentation metadata: name: instrumentation spec: resource: addK8sUIDAttributes: true exporter: endpoint: http://opentelemetry-collector:4317 propagators: - tracecontext - baggage - b3 sampler: type: parentbased_traceidratio argument: "0.25" python: env: - name: OTEL_LOG_LEVEL value: "debug" - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://opentelemetry-collector:4318 disabled_instrumentations: ["boto3"] # 新增:禁用boto3插装
更新配置后,重新应用该文件:
kubectl apply -f instrumentation.yaml
方法2:统一Boto3/Botocore版本
让应用的Boto3和Botocore版本与OpenTelemetry插装依赖的版本保持一致:
- 查看OpenTelemetry使用的Botocore版本:可以在插装后的容器中执行
pip show botocore查看具体版本,或者查阅opentelemetry-instrumentation-boto3的官方依赖清单。 - 调整应用的依赖配置(比如
requirements.txt或Dockerfile),指定匹配的版本。例如:
# requirements.txt boto3==1.28.63 botocore==1.31.63
重新构建应用镜像并部署。
方法3:通过应用注解临时禁用Boto3插装
如果不想修改全局Instrumentation配置,可以在应用的Deployment注解中直接添加环境变量,仅对当前应用禁用Boto3插装:
annotations: instrumentation.opentelemetry.io/inject-python: "instrumentation" instrumentation.opentelemetry.io/container-env-python: | [ {"name": "OTEL_PYTHON_DISABLED_INSTRUMENTATIONS", "value": "boto3"} ]
内容的提问来源于stack exchange,提问作者Đăng Lương
相关产品推荐
相关产品推荐

