.. _install_sandboxes_skywalking_tracing:

SkyWalking tracing
==================

.. sidebar:: Requirements

   .. include:: _include/docker-env-setup-link.rst

   :ref:`curl <start_sandboxes_setup_curl>`
        Used to make ``HTTP`` requests.

The SkyWalking tracing sandbox demonstrates Envoy's :ref:`request tracing <arch_overview_tracing>`
capabilities using `SkyWalking <http://skywalking.apache.org>`_ as the tracing provider. This sandbox
is very similar to the Zipkin sandbox. All containers will be deployed inside a virtual network
called ``envoymesh``.

All incoming requests are routed via the front Envoy, which is acting as a reverse proxy
sitting on the edge of the ``envoymesh`` network. Port ``8000`` is exposed
by docker compose (see :download:`docker-compose.yaml <_include/skywalking-tracing/docker-compose.yaml>`).

Notice that all Envoys are configured to collect request traces (e.g., http_connection_manager/config/tracing setup in
:download:`front-envoy-skywalking.yaml <_include/skywalking-tracing/front-envoy-skywalking.yaml>`)
and setup to propagate the spans generated by the SkyWalking tracer to a SkyWalking cluster (trace driver setup
in :download:`front-envoy-skywalking.yaml <_include/skywalking-tracing/front-envoy-skywalking.yaml>`).

When service1 accepts the request forwarded from front envoy, it will make an API call to service2 before
returning a response.

Step 1: Build the sandbox
*************************

Change to the ``examples/skywalking-tracing`` directory.

To build this sandbox example, and start the example apps run the following commands:

.. code-block:: console

    $ pwd
    envoy/examples/skywalking-tracing
    $ docker-compose pull
    $ docker-compose up --build -d
    $ docker-compose ps

                Name                              Command                State                                  Ports
    --------------------------------------------------------------------------------------------------------------------------------------------------
    skywalking-tracing_elasticsearch_1    /tini -- /usr/local/bin/do ... Up (healthy)   0.0.0.0:9200->9200/tcp, 9300/tcp
    skywalking-tracing_front-envoy_1      /docker-entrypoint.sh /bin ... Up             10000/tcp, 0.0.0.0:8000->8000/tcp, 0.0.0.0:8001->8001/tcp
    skywalking-tracing_service1_1         /bin/sh /usr/local/bin/sta ... Up             10000/tcp
    skywalking-tracing_service2_1         /bin/sh /usr/local/bin/sta ... Up             10000/tcp
    skywalking-tracing_skywalking-oap_1   bash docker-entrypoint.sh      Up (healthy)   0.0.0.0:11800->11800/tcp, 1234/tcp, 0.0.0.0:12800->12800/tcp
    skywalking-tracing_skywalking-ui_1    bash docker-entrypoint.sh      Up             0.0.0.0:8080->8080/tcp

Step 2: Generate some load
**************************

You can now send a request to service1 via the front-envoy as follows:

.. code-block:: console

    $ curl -v localhost:8000/trace/1
    *   Trying ::1...
    * TCP_NODELAY set
    * Connected to localhost (::1) port 8000 (#0)
    > GET /trace/1 HTTP/1.1
    > Host: localhost:8000
    > User-Agent: curl/7.58.0
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < content-type: text/html; charset=utf-8
    < content-length: 89
    < server: envoy
    < date: Sat, 10 Oct 2020 01:56:08 GMT
    < x-envoy-upstream-service-time: 27
    <
    Hello from behind Envoy (service 1)! hostname: 1a2ba43d6d84 resolvedhostname: 172.19.0.6
    * Connection #0 to host localhost left intact

You can get SkyWalking stats of front-envoy after some requests as follows:

.. code-block:: console

    $ curl -s localhost:8001/stats | grep tracing.skywalking
    tracing.skywalking.cache_flushed: 0
    tracing.skywalking.segments_dropped: 0
    tracing.skywalking.segments_flushed: 0
    tracing.skywalking.segments_sent: 13

Step 3: View the traces in SkyWalking UI
****************************************

Point your browser to http://localhost:8080 . You should see the SkyWalking dashboard.
Set the service to "front-envoy" and set the start time to a few minutes before
the start of the test and hit enter. You should see traces from the front-proxy.
Click on a trace to explore the path taken by the request from front-proxy to service1
to service2, as well as the latency incurred at each hop.

.. seealso::

   :ref:`Request tracing <arch_overview_tracing>`
      Learn more about using Envoy's request tracing.

   :ref:`Envoy admin quick start guide <start_quick_start_admin>`
      Quick start guide to the Envoy admin interface.

   `Apache SkyWalking <https://skywalking.apache.org>`_
      SkyWalking observability analysis platform and application performance management system.