弹性APM Opentracing在Docker apm-server上遇到CORS问题

时间:2019-07-26 00:36:52

标签: angular elasticsearch opentracing jaeger elastic-apm

给出此docker文件以设置后端服务,其中包括:elasticsearch,apm服务器,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问题:

Screenshot of CORS error

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

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

Distributed Tracing Guide

Config with RUM enabled

由于Default value is set to ['*'], which allows everything.

,因此配置似乎可以正常工作

1 个答案:

答案 0 :(得分: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"
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*"
setup.kibana.host: "kibana:5601"
setup.template.enabled: true
logging.to_files: false