1

给定这个 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 问题:

CORS 错误截图

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

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

分布式跟踪指南

启用 RUM 的配置

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

4

1 回答 1

3

尝试使用配置:

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

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

于 2019-07-29T15:58:36.620 回答