Configuration | ray-go | Spatie       

 SPATIE  

ray-go
======

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Ray-go](https://spatie.be/docs/ray-go/v1)  Configuration

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/ray-go/v1) 

  Configuration    
- [ Introduction ](https://spatie.be/docs/ray-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/ray-go/v1/installation-and-setup)
- [ Using Ray with Go ](https://spatie.be/docs/ray-go/v1/usage)
- [ Configuration ](https://spatie.be/docs/ray-go/v1/configuration)
- [ Methods ](https://spatie.be/docs/ray-go/v1/reference)
- [ Detecting and removing Ray calls ](https://spatie.be/docs/ray-go/v1/detecting-removing-ray-calls)
- [ Testing ](https://spatie.be/docs/ray-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/ray-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/ray-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/ray-go/v1/support-us)

 Configuration
=============

###  On this page 

1. [ Environment settings ](#content-environment-settings)
2. [ Remote debugging ](#content-remote-debugging)
3. [ Reporting errors ](#content-reporting-errors)
4. [ Customizing behavior ](#content-customizing-behavior)

By default, Ray is listening on `localhost:23517`. You can configure another host and port using `Config`. Start with `DefaultConfig`, change settings, then create an explicit client.

```
cfg := ray.DefaultConfig()
cfg.Host = "localhost"
cfg.Port = 23517
cfg.ProjectName = "My project"
cfg.ReportErrors = true
client, err := ray.New(cfg)
if err != nil {
    log.Fatal(err)
}
client.Send(ctx, "configured")
```

The default settings are:

FieldDefault`Host``localhost``Port``23517``Timeout`two seconds`Enabled``true``ReportErrors``false``ProjectName`empty string`RemotePath`, `LocalPath`no mapping`AlwaysSendRawValues``false``New` rejects an empty host, an out-of-range port and nonpositive timeout. Config is copied when creating the client. Changing your config afterward does not reconfigure that client. Use `Project`, `Enable`, `Disable`, `Max` and `PerSecond` for mutable session settings.

Environment settings
--------------------------------------------------------------------------------------------------------------------

Load environment variables explicitly with `ConfigFromEnv`, then apply your code settings afterward:

```
cfg, err := ray.ConfigFromEnv()
if err != nil {
    log.Fatal(err)
}
cfg.ProjectName = "Code overrides the environment"
client, err := ray.New(cfg)
if err != nil {
    log.Fatal(err)
}
client.Send(ctx, "configured")
```

Supported variables are `RAY_HOST`, `RAY_PORT`, `RAY_ENABLED`, `RAY_PROJECT_NAME`, `RAY_REMOTE_PATH`, `RAY_LOCAL_PATH` and `RAY_ALWAYS_SEND_RAW_VALUES`. Booleans accept `true`, `false`, `1` or `0`. Ports must be from 1 through 65535. Invalid settings return errors naming the variable without echoing its value. The package does not execute PHP settings files.

Remote debugging
--------------------------------------------------------------------------------------------------------

Map remote source paths to local editor paths:

```
cfg := ray.DefaultConfig()
cfg.RemotePath = "/var/www/my-project"
cfg.LocalPath = "/Users/freek/my-project"
client, err := ray.New(cfg)
if err != nil {
    log.Fatal(err)
}
client.Send(ctx, "remote")
```

Only a matching prefix is replaced, in both origins and stack frames. Transport is unencrypted HTTP. Keep the Ray port private and use an SSH tunnel for remote debugging. The default transport does not follow redirects or use environment HTTP proxies. A send attempts delivery directly, without PHP's cached availability probe.

Reporting errors
--------------------------------------------------------------------------------------------------------

When Ray is closed or unavailable, sending does not fail your application by default. Set `ReportErrors = true` to report transport failures through `Entry.Err()`. Preparation, serialization, hook and context cancellation errors are always retained. `Windows` and `Theme` always report query failures. Check `Err` at the end of fluent chains.

The first error stops later sends on that entry. Create another entry for a new operation. Panics in application callbacks propagate normally.

Customizing behavior
--------------------------------------------------------------------------------------------------------------------

PHP's custom client, origin factory, payload finder and request hooks have per-client Go equivalents:

- `Transport` replaces both delivery and app queries. Implement `Send(context.Context, ray.Request) error` and `Get(context.Context, string) (json.RawMessage, error)`. `Get` receives relative paths such as `windows`, `theme` and lock paths with query strings.
- `OriginFactory` returns a `ray.Origin` for clickable source links. Path mapping still applies. Explicit nonzero payload origins are also accepted.
- `PayloadFinder` returns a payload, whether it handled the value, and an error. Unhandled values use the built-in converter. `Raw` bypasses the finder. A finder can handle types JSON cannot serialize.
- `BeforeSend` can change the request's payloads and metadata, or return an error to stop delivery.
- `AfterSend` observes the final request after an attempted delivery, including ignored best-effort failures. It does not run after reported failures.

All callbacks may run concurrently. Synchronize callback-owned mutable state. Do not mutate requests after returning them to a transport or callback. Custom transports must honor the supplied context. The configured timeout applies to the built-in HTTP transport. A replacement transport owns its own timeout policy.

```
cfg := ray.DefaultConfig()
cfg.PayloadFinder = func(value any) (ray.Payload, bool, error) {
    if text, ok := value.(string); ok {
        return ray.Payload{Type: "custom", Content: map[string]any{
            "content": strings.ToUpper(text), "label": "Uppercase",
        }}, true, nil
    }
    return ray.Payload{}, false, nil
}
cfg.BeforeSend = func(request *ray.Request) error {
    request.Meta["tenant"] = "Spatie"
    return nil
}
client, err := ray.New(cfg)
if err != nil {
    log.Fatal(err)
}
client.Send(ctx, "customized")
```

This example also imports `strings`. Custom payload content follows the [Ray protocol](https://myray.app/docs/developing-ray-libraries/payload). Unlike PHP's static callbacks, configuration on one client does not leak into other clients. This package has no models, jobs or profiles to replace.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
