ekino / EkinoNewRelicBundle

Add NewRelic support to Symfony
MIT License
280 stars 104 forks source link

Fos HTTP Cache show as index.php #206

Open Webonaute opened 6 years ago

Webonaute commented 6 years ago

I have problem to see my cached request to display in new relic. they all show as index.php

is there a way to specially name it cached_\?

Nyholm commented 6 years ago

Sure. Have a look at the NamingStrategy section. https://github.com/ekino/EkinoNewRelicBundle#transaction-naming-strategies

Webonaute commented 6 years ago

but why my cache is see as index.php instead of routename?

here is my config. did I miss anything?

ekino_new_relic:
    enabled: true                         # Defaults to true
    application_name: 'api-%kernel.environment%' # default value in newrelic is "PHP Application", or whatever is set
                                          # as php ini-value
    deployment_names: '%api_version%'                   # default value is 'application_name', supports string array or semi-colon separated string
    api_key:  '%newrelic_api_key%'        # New Relic API
    license_key: '%newrelic_license_key%' # New Relic license key (optional, default value is read from php.ini)
    xmit: false                           # if you want to record the metric data up to the point newrelic_set_appname is called, set this to true (default: false)
    logging: false                        # If true, logs all New Relic interactions to the Symfony log (default: false)
    #interactor: Ekino\NewRelicBundle\NewRelic\AdaptiveInteractor                      # The interactor service that is used. Setting enabled=false will override this value
    twig: false                           # Allows you to disable twig integration (falls back to class_exists(\Twig_Environment::class))
    exceptions: true                      # If true, sends exceptions to New Relic (default: true)
    deprecations: false                   # If true, reports deprecations to New Relic (default: true)
    instrument: false                     # If true, uses enhanced New Relic RUM instrumentation (see below) (default: false)
    http:
        enabled: true
        using_symfony_cache: true        # Symfony HTTP cache (see below) (default: false)
        transaction_naming: route         # route, controller or service (see below)
    #    transaction_naming_service: ~     # Transaction naming service (see below)
    #    ignored_routes: []                # No transaction recorded for this routes
    #    ignored_paths: []                 # No transaction recorded for this paths
    #monolog:
    #    enabled: false                    # When enabled, send application's logs to New Relic (default: disabled)
    #    channels: [app]                   # Channels to listen (default: null). [See Symfony's documentation](http://symfony.com/doc/current/logging/channels_handlers.html#yaml-specification)
    #    level: error                      # Report only logs higher than this level (see \Psr\Log\LogLevel) (default: error)
    #    service: app.my_custom_handler    # Define a custom log handler (default: ekino.new_relic.monolog_handler)
    commands:
        enabled: true                     # If true, logs CLI commands to New Relic as Background jobs (>2.3 only) (default: true)
        ignored_commands: []              # No transaction recorded for this commands (background tasks)
Webonaute commented 5 years ago

from what I see, the RequestListener is never trigger on cached request. so the transaction name cannot be set.

jderusse commented 5 years ago

Hmm.. are you using SymfonyCache?

If yes, Symfony is probably returning the cached response before calling the NewrelicBundle's code. That would explain why the transaction is not defined.

Webonaute commented 5 years ago

Yeah. That’s what I found. I am using FoshttpCache bundle. Look like I need a special subscriber in my AppCache setup.

jderusse commented 5 years ago

Thinking about your issue, IMHO, this is a good thing that the RequestListener is not called. First, for performance reason, but mainly because NewRelic should not mix metrics from cached response with not-cached.

I think you may try to set a ReverseCache temporary name in the Kernel's handle function. This name will be overrided by the RequestListener for Missed calls, and it'll stay a default name for Cached responses.

class CacheKernel extends HttpCache
{
  public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) {
    newrelic_name_transaction('cached');
    // or with NR objects: (new AdaptiveInteractor(new NewRelicInteractor(), new BlackholeInteractor))->setTransactionName('cached');

    return parent::handle($request, $type, $catch);
  }
}

Could you give a try and tell us if it works for you? We'll add an entry in the documentation

Webonaute commented 5 years ago

already try to handle the transaction name in the handle method, it's not applied.