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

How to make telescope tenant aware? #70

Closed
aminraeisi opened this issue Jun 30, 2020 · 14 comments
Closed

How to make telescope tenant aware? #70

aminraeisi opened this issue Jun 30, 2020 · 14 comments

Comments

@aminraeisi
Copy link

How can I make telescope tenant aware? here is the part that throws error because 'mysql' is no longer available but instead the name is dynamic:

'driver' => env('TELESCOPE_DRIVER', 'database'),

    'storage' => [
        'database' => [
            'connection' => env('DB_CONNECTION', 'mysql'),
            'chunk' => 1000,
        ],
    ],
@masterix21
Copy link
Collaborator

My suggestion is to keep working telescope on the landlord connection. Next, create a tag for Telescope when you switch a tenant.

I will create a TelescopeSwitchTenantTask in the next PR, and I hope that will be merged.

@aminraeisi
Copy link
Author

@masterix21 thanks! I will wait for that 😄

@masterix21
Copy link
Collaborator

masterix21 commented Jun 30, 2020

@aminraeisi try something like this:

class SwitchTenantTelescopeTask implements SwitchTenantTask
{
    protected ?array $originalTelescopeTagUsing;

    public function makeCurrent(Tenant $tenant): void
    {
        $this->originalTelescopeTagUsing = Telescope::$tagUsing;

        Telescope::$tagUsing = [];
        Telescope::tag(fn () => [ $tenant->domain ]);
    }

    public function forgetCurrent(): void
    {
        Telescope::$tagUsing = $this->originalTelescopeTagUsing;
        Telescope::tag(fn () => [ 'landlord' ]);
    }
}

@aminraeisi
Copy link
Author

Thanks for your time! What does this supposed to do? is it for tagging the telescope entries (assuming I need to move the telescope migrations to landlord)?

@masterix21
Copy link
Collaborator

Yes!

I think that the best way to use Telescope is in only one database (landlord), then when you need to track a request or anything else about a Tenant, you can simply add a "tag" to Telescope. Will works like a charm :)

@aminraeisi
Copy link
Author

It worked! Please update $tenant->host to $tenant->domain as it made me spend 1 hour to find out why it is not tagging them 🤣

@masterix21
Copy link
Collaborator

Haha, sorry, I made a mistake because I'm using "host" and not "domain" in my project.

Thanks.

@aminraeisi
Copy link
Author

Thanks for that! one more thing, It did not tag the non-tenant requests. I can put space to detect them but it would be better if the default is landlord.

@masterix21
Copy link
Collaborator

Doesn't works using "landlord" as tag?

@aminraeisi
Copy link
Author

Each tenant has subdomain and visiting tenant1.site.com will tag the request with tenant1.site.com but when I go to the main site.com the request does not get any tags and I want to get 'landlord' tag for it.

@masterix21
Copy link
Collaborator

Ok. What happen if you add Telescope::tag(fn () => [ 'landlord' ]); to your AppServiceProvider boot method?

@aminraeisi
Copy link
Author

That adds the landlord tag to all the requests even if it is a tenant request. So I need to remove it somehow when it is on the tenant? Or we don't have tasks to run when no tenant is selected? I mean when the request is to the main landlord site?

@aminraeisi
Copy link
Author

Adding this to AppServiceProvider worked:

!Tenant::current() ? Telescope::tag(fn () => ['landlord']): '';

So it will only add the landlord tag if we do not have a current tenant. Thanks a lot for your help.

@masterix21
Copy link
Collaborator

Well ;)

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

No branches or pull requests

2 participants