【问题标题】:Elastic APM Opentracing encountering CORS issue with Docker apm-serverElastic APM Opentracing 遇到 Docker apm-server 的 CORS 问题
【发布时间】:2019-07-26 00:36:52
【问题描述】:

给定这个 docker 文件来设置后端服务,包括:elasticsearch、apm-server、kibana、jaeger-collector、jaeger-agent、jaeger-query、grafana。

apm-server:
image: docker.elastic.co/apm/apm-server:6.8.1
ports:
  - 8200:8200
environment:
  - output.elasticsearch.hosts=['http://elasticsearch:9200']
  - apm-server.host="0.0.0.0:8200"
  - apm-server.rum.enabled=true
  - setup.kibana.host="kibana:5601"
  - setup.template.enabled=true
  - logging.to_files=false
networks:
  - elastic-jaeger

我正在从我的 Angular 客户端运行带有 Opentracing 的 Elastic APM:

const elasticApm = initApm({
  serviceName: `Test`,
  serviceUrl: `127.0.0.1:8200`,
  // serviceVersion: ``,
  active: true,
  environment: ``, // production, development, test, etc
  logLevel: `warn`, // Possible levels are: trace, debug, info, warn, error
  flushInterval: 500, // ms
  errorThrottleLimit: 20, // errors
  errorThrottleInterval: 30000, // ms
  transactionSampleRate: 1.0,
  distributedTracing: true,
  distributedTracingOrigins: ['http://foo.com']
});

const elasticTracer = createTracer(elasticApm);
this.opentracing.initGlobalTracer(elasticTracer);

我遇到了 CORS 问题:

我的目标是将 Angular 和弹性 APM 的 opentracing 客户端连接到 docker 内的服务。

还有一些额外的问题和文档涵盖了 apm-server 的 CORS:

Distributed Tracing Guide

Config with RUM enabled

看起来配置应该可以工作,因为Default value is set to ['*'], which allows everything.

【问题讨论】:

    标签: angular elasticsearch opentracing jaeger elastic-apm


    【解决方案1】:

    尝试使用配置:

    version: "3"
    
    services:
      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.8.1
        networks:
          - elastic-jaeger
        ports:
          - "127.0.0.1:9200:9200"
          - "127.0.0.1:9300:9300"
        restart: on-failure
        environment:
          - cluster.name=jaeger-cluster
          - discovery.type=single-node
          - http.host=0.0.0.0
          - transport.host=127.0.0.1
          - ES_JAVA_OPTS=-Xms512m -Xmx512m
          - xpack.security.enabled=false
        volumes:
          - esdata:/usr/share/elasticsearch/data
    
      apm-server:
        image: docker.elastic.co/apm/apm-server:6.8.1
        ports:
          - 8200:8200
    
        volumes:
           - ./apm-server/config/apm-server.yml:/usr/share/apm-server/apm-server.yml
    
        networks:
          - elastic-jaeger
    
      kibana:
        image: docker.elastic.co/kibana/kibana:6.8.1
        ports:
          - "127.0.0.1:5601:5601"
        restart: on-failure
        networks:
          - elastic-jaeger
    
      jaeger-collector:
        image: jaegertracing/jaeger-collector
        ports:
          - "14269:14269"
          - "14268:14268"
          - "14267:14267"
          - "9411:9411"
        networks:
          - elastic-jaeger
        restart: on-failure
        environment:
          - SPAN_STORAGE_TYPE=elasticsearch
        command: [
          "--es.server-urls=http://elasticsearch:9200",
          "--es.num-shards=1",
          "--es.num-replicas=0",
          "--log-level=error"
        ]
        depends_on:
          - elasticsearch
    
      jaeger-agent:
        image: jaegertracing/jaeger-agent
        hostname: jaeger-agent
        command: ["--collector.host-port=jaeger-collector:14267"]
        ports:
          - "5775:5775/udp"
          - "6831:6831/udp"
          - "6832:6832/udp"
          - "5778:5778"
        networks:
          - elastic-jaeger
        restart: on-failure
        environment:
          - SPAN_STORAGE_TYPE=elasticsearch
        depends_on:
          - jaeger-collector
    
      jaeger-query:
        image: jaegertracing/jaeger-query
        environment:
          - SPAN_STORAGE_TYPE=elasticsearch
          - no_proxy=localhost
        ports:
          - "16686:16686"
          - "16687:16687"
        networks:
          - elastic-jaeger
        restart: on-failure
        command: [
          "--es.server-urls=http://elasticsearch:9200",
          "--span-storage.type=elasticsearch",
          "--log-level=debug"
        ]
        depends_on:
          - jaeger-agent
    
      grafana:
        image: grafana/grafana
        ports:
          - 3999:3000
        volumes:
          - ./grafana-data:/var/lib/grafana
        networks:
          - elastic-jaeger
    
    volumes:
      esdata:
        driver: local
    
    networks:
      elastic-jaeger:
        driver: bridge 
    
    

    文件 apm-server/config/apm-server.yml 包含您的配置内容:

    apm-server.rum.enabled: true
    apm-server.rum.event_rate.limit: 300
    apm-server.rum.event_rate.lru_size: 1000
    apm-server.rum.allow_origins: ['*']
    apm-server.rum.library_pattern: "node_modules|bower_components|~"
    apm-server.rum.exclude_from_grouping: "^/webpack"
    apm-server.rum.source_mapping.cache.expiration: 5m
    apm-server.rum.source_mapping.index_pattern: "apm-*-sourcemap*"
    output.elasticsearch.hosts: ["http://elasticsearch:9200"]
    apm-server.host: "0.0.0.0:8200"
    setup.kibana.host: "kibana:5601"
    setup.template.enabled: true
    logging.to_files: false
    
    

    注意 rum.allow_origins 选项,您可以配置该选项来解决 CORS 问题。 https://www.elastic.co/guide/en/apm/agent/rum-js/master/configuring-cors.html

    【讨论】:

    • 不清楚修复是什么,好像你只是复制粘贴了一些东西,apm-server-yml 看起来有重复条目?
    • 感谢@EdgarQuintero。我更新了答案以清理配置中的重复项,并指出了我认为相关的答案部分的注释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多