Skip to content

Commit

Permalink
docs(getstarted): add php trace ingestion + sample
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanrahic committed Oct 22, 2024
1 parent 6b281e6 commit 9612b0b
Show file tree
Hide file tree
Showing 64 changed files with 11,052 additions and 14 deletions.
55 changes: 53 additions & 2 deletions docs/docs/getting-started/configure-trace-ingestion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
id: configure-trace-ingestion
title: Configure Trace Ingestion
description: Get started by configuring trace ingestion to connect traces to tests. Tracetest allows you to quickly build integration and end-to-end tests, powered by your OpenTelemetry traces.
hide_table_of_contents: false
hide_table_of_contents: true
keywords:
- tracetest
- trace-based testing
Expand Down Expand Up @@ -436,6 +436,57 @@ rails server -p 8080
[Visit the example in GitHub, here.](https://github.com/kubeshop/tracetest/tree/main/examples/getting-started/ruby)
:::

</TabItem>
<TabItem value="php" label="PHP">

1. Install OpenTelemetry Extension for PHP

```bash title="Terminal"
pecl install opentelemetry
```

2. Install `composer` if not installed already

```bash title="Terminal"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

# If you want to use Composer globally from any directory, move it to a directory in your PATH:
sudo mv composer.phar /usr/local/bin/composer
composer --version
```

3. Install OpenTelemetry SDK for your libraries

[View all libraries here.](https://packagist.org/search/?query=open-telemetry&tags=instrumentation) The example below showcases Laravel.

```bash
composer require \
open-telemetry/sdk \
open-telemetry/exporter-otlp \
open-telemetry/opentelemetry-auto-laravel
# ...
```

4. Configure OpenTelemetry in `php.ini`

```ini
[opentelemetry]
extension=opentelemetry.so

OTEL_PHP_AUTOLOAD_ENABLED="true"
OTEL_SERVICE_NAME=your-php-app
OTEL_TRACES_EXPORTER=otlp
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
OTEL_PROPAGATORS=baggage,tracecontext
```

:::note View a code sample
[Visit the example in GitHub, here.](https://github.com/kubeshop/tracetest/tree/main/examples/getting-started/php)
:::

</TabItem>
<TabItem value="browser" label="Browser">

Expand Down Expand Up @@ -625,7 +676,7 @@ spec:
This will automatically instrument your service with OpenTelemetry and send the traces to the OpenTelemetry collector.

</TabItem>
<TabItem value="otelcol" label="OTel Collector">
<TabItem value="otelcol" label="OpenTelemetry&nbsp;Collector">

You can configure OpenTelemetry SDKs to export traces to an [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) first. Then, configure an exporter and service pipeline to forward traces to Tracetest.

Expand Down
25 changes: 14 additions & 11 deletions docs/docs/getting-started/create-response-based-test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
id: create-response-based-test
title: Create a Response-based Test
description: Get started by creating a response-based test in Tracetest! Tracetest allows you to quickly build integration and end-to-end tests, powered by your OpenTelemetry traces.
hide_table_of_contents: false
hide_table_of_contents: true
keywords:
- tracetest
- trace-based testing
Expand All @@ -21,16 +21,18 @@ import TabItem from '@theme/TabItem';
import CodeBlock from '@theme/CodeBlock';
import GtagInstallCliTabs from '@site/src/components/GtagInstallCliTabs';

To create a test, you define a `trigger`. A trigger is an action that executes an action against your system. The most basic trigger is an HTTP requests, but we support several trigger types.
To create a test, you define a `trigger`. A trigger is an action that executes an action against your system.

1. Playwright
2. HTTP
3. GRPC
4. GraphQL
5. Kafka
The most basic trigger is an HTTP requests, but Tracetest supports several trigger types.

1. HTTP
2. GRPC
3. GraphQL
4. Kafka
5. Playwright

:::note
Playwright enables a useful technique: True end-to-end testing, where you start tests from the Web UI and explore the entire internal process of that request across the back end, database, and external services.
[Playwright enables a useful technique](/examples-tutorials/recipes/running-tests-with-tracetest-playwright-engine): True end-to-end testing, where you start tests from the Web UI and explore the entire internal process of that request across the back end, database, and external services.
:::

You can create tests in two ways:
Expand Down Expand Up @@ -68,8 +70,9 @@ tracetest run test -f ./ping-google.yaml

Create a test in the Web UI by opening your Tracetest Account, clicking the Create button, and selecting HTTP.

![create response based test 1](https://res.cloudinary.com/djwdcmwdz/image/upload/v1727177155/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_ed85b0979257d37b_tests_page_1_qc1291.png)

Enter `https://google.com` as the URL, and click Run.

![create response based test 2](https://res.cloudinary.com/djwdcmwdz/image/upload/v1727177429/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_ed85b0979257d37b_tests_page_1_1_qpqa4w.png)
<p align="center">
<img src="https://res.cloudinary.com/djwdcmwdz/image/upload/v1727177155/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_ed85b0979257d37b_tests_page_1_qc1291.png" alt="test 1" width="50%" />
<img src="https://res.cloudinary.com/djwdcmwdz/image/upload/v1727177429/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_ed85b0979257d37b_tests_page_1_1_qpqa4w.png" alt="test 2" width="50%" />
</p>
2 changes: 1 addition & 1 deletion docs/docs/getting-started/install-agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import GtagInstallCliTabs from '@site/src/components/GtagInstallCliTabs';
1. Run tests against your apps.
2. Ingest traces from your apps.

This page explains (1), how to start Tracetest Agent to enable running tests against your apps. Tracetest Agent can run either locally on your machine or as a container in Docker or Kubernetes.
This page explains (1), how to start Tracetest Agent (locally on your machine or as a container) to enable running tests against your apps.

<Tabs groupId="installation">
<TabItem value="cli" label="Tracetest CLI" default>
Expand Down
18 changes: 18 additions & 0 deletions examples/getting-started/php/hello-world-api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
66 changes: 66 additions & 0 deletions examples/getting-started/php/hello-world-api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database

PHP_CLI_SERVER_WORKERS=4

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=

SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database

CACHE_STORE=database
CACHE_PREFIX=

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"
11 changes: 11 additions & 0 deletions examples/getting-started/php/hello-world-api/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto eol=lf

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
22 changes: 22 additions & 0 deletions examples/getting-started/php/hello-world-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/storage/pail
/vendor
.env
.env.backup
.env.production
.phpactor.json
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
/.zed
66 changes: 66 additions & 0 deletions examples/getting-started/php/hello-world-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>

<p align="center">
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>

## About Laravel

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:

- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).

Laravel is accessible, powerful, and provides tools required for large, robust applications.

## Learning Laravel

Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.

You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.

If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.

## Laravel Sponsors

We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).

### Premium Partners

- **[Vehikl](https://vehikl.com/)**
- **[Tighten Co.](https://tighten.co)**
- **[WebReinvent](https://webreinvent.com/)**
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
- **[64 Robots](https://64robots.com)**
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
- **[Cyber-Duck](https://cyber-duck.co.uk)**
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
- **[Jump24](https://jump24.co.uk)**
- **[Redberry](https://redberry.international/laravel/)**
- **[Active Logic](https://activelogic.com)**
- **[byte5](https://byte5.de)**
- **[OP.GG](https://op.gg)**

## Contributing

Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).

## Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).

## Security Vulnerabilities

If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [[email protected]](mailto:[email protected]). All security vulnerabilities will be promptly addressed.

## License

The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Http\Controllers;

abstract class Controller
{
//
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HelloWorldController extends Controller
{
public function index()
{
return response()->json(['message' => 'Hello, World!']);
}
}
48 changes: 48 additions & 0 deletions examples/getting-started/php/hello-world-api/app/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}
Loading

0 comments on commit 9612b0b

Please sign in to comment.