Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom tag is not showing up in Telescope dashboard #830

Closed
buismaarten opened this issue Feb 20, 2020 · 15 comments
Closed

Custom tag is not showing up in Telescope dashboard #830

buismaarten opened this issue Feb 20, 2020 · 15 comments
Assignees

Comments

@buismaarten
Copy link

  • Telescope Version: 3.0.0
  • Laravel Version: 6.16.0
  • PHP Version: 7.4.1
  • Database Driver & Version: 5.7.28-0ubuntu0.18.04.4 - (Ubuntu)

Description:

Custom tag is not showing up in Telescope dashboard.

Telescope::tag(function (IncomingEntry $entry) {
    if ($entry->type === 'request') {
        return ['status:'.$entry->content['response_status']];
    }

    return [];
});

Steps To Reproduce:

  • Install Laravel 6.0
  • Install Telescope
  • Define custom tag
  • Preview a Request in Telescope dashboard
@ManojKiranA
Copy link

Yes i can reproduce it. its definitely a Bug.

ping @themsaid @driesvints

@buismaarten
Copy link
Author

buismaarten commented Feb 21, 2020

Fixed the issue using the following code:

Telescope::filter(function (IncomingEntry $entry) {
            if ($entry->type === EntryType::EXCEPTION) {
                $entry->tags([
                    $entry->content['class'],
                ]);
            }

            if ($entry->type === EntryType::MAIL) {
                $entry->tags([
                    $entry->content['mailable'],
                ]);
            }

            if ($entry->type === EntryType::REQUEST) {
                $entry->tags([
                    $entry->content['uri'],
                    $entry->content['method'],
                    $entry->content['response_status'],
                    $entry->content['controller_action'],
                ]);
            }

            if ($entry->type === EntryType::VIEW) {
                $entry->tags([
                    $entry->content['path'],
                ]);
            }

            return true;
        });

Much cleaner in my opinion, is this the way to go or is it recommended to use the code from the documentation?

@themsaid
Copy link
Member

themsaid commented Feb 21, 2020

I can't replicate:

Telescope::tag(function(IncomingEntry $entry){
    if ($entry->type === 'request') {
        return ['status:'.$entry->content['response_status']];
    }

    return [];
});

Screen Shot 2020-02-21 at 3 27 29 PM

@buismaarten
Copy link
Author

buismaarten commented Feb 21, 2020

Can you tell me some information about your environment, are you using Laravel 7 or something? @themsaid

@ManojKiranA
Copy link

ManojKiranA commented Feb 24, 2020

@themsaid your above code doesn't

Configuration:

Laravel Framework 6.16.0 (Fresh Installation)
Laravel Telescope v3.0.0

My Provider File:

<?php

namespace App\Providers;

use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Str;
use Laravel\Telescope\EntryType;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeApplicationServiceProvider;

class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        Telescope::night();

        $this->hideSensitiveRequestDetails();

        Telescope::filter(function (IncomingEntry $entry) {
            if (App::isLocal()) {
                return true;
            }

            return $entry->isReportableException() ||
                   $entry->isFailedRequest() ||
                   $entry->isFailedJob() ||
                   $entry->isScheduledTask() ||
                   $entry->hasMonitoredTag();
        });

        Telescope::tag(function (IncomingEntry $entry) {
            $entryContent = $entry->content;

            if ($entry->type === EntryType::CACHE) {
                $cacheTags = [
                    'Action:'.$entryContent['type'],
                    'Key:'.$entryContent['key'],
                    $entryContent['key'].':'.$entryContent['type'],
                ];

                return $cacheTags;
            }

            if ($entry->type === EntryType::VIEW) {
                $viewTags = [
                    'File:'.str_replace(['/', '\\'], [DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], $entryContent['path']),
                    'FileRealPath:'.base_path().str_replace(['/', '\\'], [DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], $entryContent['path']),
                ];

                return $viewTags;
            }

            if ($entry->type === EntryType::REQUEST) {
                $authUserTag = [];

                if (Auth::check()) {
                    $authorizedUser = Auth::user();
                    $authUserTag = [
                        'Email:'.$authorizedUser->email,
                        'Name:'.$authorizedUser->name,
                    ];
                }

                $requestTags = [
                    'Method:'.$entryContent['method'],
                    'Status:'.$entryContent['response_status'],
                    'IP:'.request()->ip(),
                ];

                return array_merge($requestTags, $authUserTag);
            }
            if ($entry->type === EntryType::MODEL) {
                $modelName = Str::before($entryContent['model'], ':');
                $modelAction = ucfirst($entryContent['action']);
                $modelTags = [
                    'ModelAction:'.$modelAction,
                    'ModelName:'.$modelName,
                    $modelName.':'.$modelAction,
                ];

                return $modelTags;
            }

            return [];
        });
    }

    /**
     * Prevent sensitive request details from being logged by Telescope.
     *
     * @return void
     */
    protected function hideSensitiveRequestDetails()
    {
        if (App::isLocal()) {
            return;
        }

        Telescope::hideRequestParameters(['_token']);

        Telescope::hideRequestHeaders([
            'cookie',
            'x-csrf-token',
            'x-xsrf-token',
        ]);
    }

    /**
     * Register the Telescope gate.
     *
     * This gate determines who can access Telescope in non-local environments.
     *
     * @return void
     */
    protected function gate()
    {
        Gate::define('viewTelescope', function ($user) {
            return in_array($user->email, [
                //
            ]);
        });
    }
}

Its not tagging anything.

Here is repo

https://github.com/ManojKiranA/telescopeissue

@buismaarten
Copy link
Author

Thanks!

Tried your repo, doesn't work on my machine.

image

@ManojKiranA
Copy link

@buismaarten have you tried my repo

@buismaarten
Copy link
Author

@ManojKiranA yes, see the screenshot above and didn't changed anything in the code.

@ManojKiranA
Copy link

yes, see the screenshot above and didn't changed anything in the code.

Let's wait for @themsaid @driesvints

@themsaid
Copy link
Member

@ManojKiranA could you test a simple example?

Telescope::tag(function(IncomingEntry $entry){
    if ($entry->type === 'request') {
        return ['status:'.$entry->content['response_status']];
    }

    return [];
});

The example above works for me. Please show me how I can replicate the issue with a simple example like this one.

@ManojKiranA
Copy link

@themsaid still the same i have updated my repo check that

and While returing a empty array and while i was trying to migrate the tables

here is the exception thrown


   ErrorException  : Array to string conversion

  at C:\xampp\htdocs\telescopetest\vendor\laravel\telescope\src\IncomingEntry.php:164
    160|      * @return $this
    161|      */
    162|     public function tags(array $tags)
    163|     {
  > 164|         $this->tags = array_unique(array_merge($this->tags, $tags));
    165| 
    166|         return $this;
    167|     }
    168| 

  Exception trace:

  1   array_unique()
      C:\xampp\htdocs\telescopetest\vendor\laravel\telescope\src\IncomingEntry.php:164

  2   Laravel\Telescope\IncomingEntry::tags()
      C:\xampp\htdocs\telescopetest\vendor\laravel\telescope\src\Telescope.php:255

  Please use the argument -v to see more details.

@clementai
Copy link

@ManojKiranA same here with the empty array #831

@themsaid
Copy link
Member

fixed in #839

@sanaat
Copy link

sanaat commented Nov 11, 2020

Telescope version "laravel/telescope": "^3.5", Authenticated User block show new field PhoneNumber but not displayed can you any one help me
image

@driesvints
Copy link
Member

@sanaat Telescope 3.x isn't supported anymore. Please upgrade to the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants