arkaitzgarro / elastic-apm-laravel

Laravel APM agent for Elastic v2 intake API
MIT License
79 stars 17 forks source link

Apm setup #155

Closed thewasta closed 2 years ago

thewasta commented 2 years ago

Enviroment: Laravel v8

This is my current config/elastic-apm-laravel.php

<?php

return [
    'active' => true,
    'log-level' => "DEBUG", //tried info,error
    'cli' => [
        'active' => env('APM_ACTIVE_CLI', true),
    ],
    'app' => [
        'serviceName' => preg_replace('/[^a-zA-Z0-9 _-]/', '-', "laravel"),
        'serviceVersion' => 7.14
    ],
    'env' => [
        'env' => ['DOCUMENT_ROOT', 'REMOTE_ADDR'],
        'environment' => "development"
    ],
    'server' => [
        'serverUrl' => "http://localhost:8200",
        'hostname' => env('ELASTIC_APM_HOSTNAME', gethostname()),
    ],
    'agent' => [
        'transactionSampleRate' => env('ELASTIC_APM_TRANSACTION_SAMPLE_RATE', 1),
    ],
    'transactions' => [
        'useRouteUri' => env('APM_USEROUTEURI', true),
        'ignorePatterns' => env('APM_IGNORE_PATTERNS', null),
    ],
    'spans' => [
        'maxTraceItems' => env('APM_MAXTRACEITEMS', 1000),
        'backtraceDepth' => env('APM_BACKTRACEDEPTH', env('ELASTIC_APM_STACK_TRACE_LIMIT', 25)),
        'querylog' => [
            'enabled' => true,
            'threshold' => env('APM_THRESHOLD', 200),
        ],
    ],
];
// I know I must to use env variables, but want to let you know values

My docker-compose.yml

version: '3'

networks:
  laravel:

services:
  kibana:
    image: kibana:7.14.0
    container_name: kibana
    volumes:
      - ./kibana/kibana.yml:/usr/share/kibana/config/kibana.yml
    ports:
      - "5601:5601"
    depends_on:
      - elastic
    networks:
      - laravel

  elastic:
    image: elasticsearch:7.14.0
    hostname: elasticsearch
    container_name: elastic
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - ./elastic/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - ./elastic/data:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - laravel
  apm:
    image: elastic/apm-server:7.14.0
    cap_add: [ "CHOWN", "DAC_OVERRIDE", "SETGID", "SETUID" ]
    cap_drop: [ "ALL" ]
    container_name: apm
    hostname: apm_agent
    ports:
      - "8200:8200"
    depends_on:
      - elastic
      - kibana
    networks:
      - laravel
    command: >
      apm-server -e
        -E apm-server.rum.enabled=true
        -E setup.kibana.host=kibana:5601
        -E setup.template.settings.index.number_of_replicas=0
        -E apm-server.kibana.enabled=true
        -E apm-server.kibana.host=kibana:5601
        -E output.elasticsearch.hosts=["elasticsearch:9200"]
    healthcheck:
      interval: 10s
      retries: 12
      test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/

elasticsearch.yml

cluster.name: "docker-cluster"
network.host: 0.0.0.0
discovery.type: "single-node"
node.name: "elastic_node"
xpack.security.enabled: false
bootstrap.memory_lock: true

I installed php-http/guzzle7-adapter and arkaitzgarro/elastic-apm-laravel tried some request (go to home page...) but no services listed (Kibana->Observability->APM/Services), and no errors on logs. Used elastic:create command from jeroen-g/explorer library, and one service is listed but only my command. Tried to throw a error from my application, but not listed on error. I added AG\ElasticApmLaravel\Middleware\RecordTransaction to Http/Kernel.php middleware. Did I miss something?

I want to trace request, DB queries, errors, cpu usage...

countless-integers commented 2 years ago

Can you try adding the token to authenticate with Elastic too? See this for reference. You can also check you Laravel logs for errors.

thewasta commented 2 years ago

Can you try adding the token to authenticate with Elastic too? See this for reference. You can also check you Laravel logs for errors.

But, I have not security on my stack. Just a single-node elasticsearch+kibana+apm. In fact it's a docker-compose

arkaitzgarro commented 2 years ago

Hi @thewasta,

I don't think we can help you, it seems a problem with your setup rather than a library problem. If you find the issue, and it's related to this package, please let us know and we will fix it.

thewasta commented 2 years ago

Hi @arkaitzgarro, But, Is my configuration ok? Did I miss something? I have been reading apm setup from elasticsearch and their guide have to install a apm agent (rpm -ivh <package-file>.rpm or deb or apk). I think my configuration is ok, otherwise I could read errors in logs. I only got one error saying to change "appName" to "serviceName" in config/elastic-apm-laravel.php nothing else.