Repository: beatlabs/patron
Pull request #151 (2020-02-08 15:34:03)

Introduce component and client packages
## Which problem is this PR solving?

Solves #150.

## Short description of the changes

- [x] Moved amqp client
- [x] Moved http client
- [x] Moved kafka client
- [x] Moved es client
- [x] Moved redis client
- [x] Moved sns client
- [x] Moved sql client
- [x] Moved sqs client
- [x] Moved async component and consumers
- [x] Moved HTTP component
- [x] Separate trace in HTTP server and client component
- [x] gRPC component
- [x] gRPC client

nstratos: # [Codecov](https://codecov.io/gh/beatlabs/patron/pull/151?src=pr&el=h1) Report
> Merging [#151](https://codecov.io/gh/beatlabs/patron/pull/151?src=pr&el=desc) into [master](https://codecov.io/gh/beatlabs/patron/commit/4c0b2d390d5de0b7fffafa1abd7b8119f9593e29&el=desc) will **decrease** coverage by `0.07%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/beatlabs/patron/pull/151/graphs/tree.svg?width=650&height=150&src=pr&token=sxY15rXW1X)](https://codecov.io/gh/beatlabs/patron/pull/151?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #151      +/-   ##
==========================================
- Coverage   80.00%   79.92%   -0.08%     
==========================================
  Files          47       47              
  Lines        2556     2556              
==========================================
- Hits         2045     2043       -2     
- Misses        449      450       +1     
- Partials       62       63       +1     
```


| [Impacted Files](https://codecov.io/gh/beatlabs/patron/pull/151?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [async/kafka/simple/simple.go](https://codecov.io/gh/beatlabs/patron/pull/151/diff?src=pr&el=tree#diff-YXN5bmMva2Fma2Evc2ltcGxlL3NpbXBsZS5nbw==) | `87.65% <0.00%> (-2.47%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/beatlabs/patron/pull/151?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/beatlabs/patron/pull/151?src=pr&el=footer). Last update [4c0b2d3...59d22d3](https://codecov.io/gh/beatlabs/patron/pull/151?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/cache/redis/redis.go b/cache/redis/redis.go
index 506d8a7db..c7bca7dde 100644
--- a/cache/redis/redis.go
+++ b/cache/redis/redis.go
@@ -4,7 +4,7 @@ import (
 	"context"
 	"time"
 
-	"github.com/beatlabs/patron/trace/redis"
+	"github.com/beatlabs/patron/client/redis"
 )
 
 // Cache encapsulates a Redis-based caching mechanism,
diff --git a/trace/amqp/amqp.go b/client/amqp/amqp.go
similarity index 100%
rename from trace/amqp/amqp.go
rename to client/amqp/amqp.go
diff --git a/trace/amqp/amqp_test.go b/client/amqp/amqp_test.go
similarity index 100%
rename from trace/amqp/amqp_test.go
rename to client/amqp/amqp_test.go
diff --git a/trace/amqp/option.go b/client/amqp/option.go
similarity index 100%
rename from trace/amqp/option.go
rename to client/amqp/option.go
diff --git a/trace/amqp/option_test.go b/client/amqp/option_test.go
similarity index 100%
rename from trace/amqp/option_test.go
rename to client/amqp/option_test.go
diff --git a/trace/amqp/user.pb.go b/client/amqp/user.pb.go
similarity index 100%
rename from trace/amqp/user.pb.go
rename to client/amqp/user.pb.go
diff --git a/trace/amqp/user.proto b/client/amqp/user.proto
similarity index 100%
rename from trace/amqp/user.proto
rename to client/amqp/user.proto
diff --git a/trace/es/elasticsearch.go b/client/es/elasticsearch.go
similarity index 96%
rename from trace/es/elasticsearch.go
rename to client/es/elasticsearch.go
index de78100db..8154a942b 100644
--- a/trace/es/elasticsearch.go
+++ b/client/es/elasticsearch.go
@@ -10,7 +10,6 @@ import (
 	"strings"
 
 	"github.com/beatlabs/patron/trace"
-	trace_http "github.com/beatlabs/patron/trace/http"
 	"github.com/elastic/go-elasticsearch/v8"
 	"github.com/elastic/go-elasticsearch/v8/esapi"
 	"github.com/elastic/go-elasticsearch/v8/estransport"
@@ -73,7 +72,9 @@ func endSpan(sp opentracing.Span, rsp *http.Response) {
 	// In cases where more than one host is given, the selected one is only known at this time
 	sp.SetTag(respondentTag, rsp.Request.URL.Host)
 
-	trace_http.FinishSpan(sp, rsp.StatusCode)
+	ext.HTTPStatusCode.Set(sp, uint16(rsp.StatusCode))
+	ext.Error.Set(sp, rsp.StatusCode >= http.StatusInternalServerError)
+	sp.Finish()
 }
 
 type transportClient struct {
diff --git a/trace/es/elasticsearch_test.go b/client/es/elasticsearch_test.go
similarity index 100%
rename from trace/es/elasticsearch_test.go
rename to client/es/elasticsearch_test.go
diff --git a/trace/http/http.go b/client/http/http.go
similarity index 91%
rename from trace/http/http.go
rename to client/http/http.go
index af6ce5bf8..dcdc5679c 100644
--- a/trace/http/http.go
+++ b/client/http/http.go
@@ -86,8 +86,7 @@ func (tc *TracedClient) do(req *http.Request) (*http.Response, error) {
 	return r.(*http.Response), nil
 }
 
-// Span starts a new HTTP span.
-func Span(path, corID string, r *http.Request) (opentracing.Span, *http.Request) {
+func span(path, corID string, r *http.Request) (opentracing.Span, *http.Request) {
 	ctx, err := opentracing.GlobalTracer().Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header))
 	if err != nil && err != opentracing.ErrSpanContextNotFound {
 		log.Errorf("failed to extract HTTP span: %v", err)
@@ -95,14 +94,13 @@ func Span(path, corID string, r *http.Request) (opentracing.Span, *http.Request)
 	sp := opentracing.StartSpan(opName(r.Method, path), ext.RPCServerOption(ctx))
 	ext.HTTPMethod.Set(sp, r.Method)
 	ext.HTTPUrl.Set(sp, r.URL.String())
-	ext.Component.Set(sp, "http")
+	ext.Component.Set(sp, clientComponent)
 	sp.SetTag(trace.VersionTag, trace.Version)
 	sp.SetTag(correlation.ID, corID)
 	return sp, r.WithContext(opentracing.ContextWithSpan(r.Context(), sp))
 }
 
-// FinishSpan finishes a HTTP span by providing a HTTP status code.
-func FinishSpan(sp opentracing.Span, code int) {
+func finishSpan(sp opentracing.Span, code int) {
 	ext.HTTPStatusCode.Set(sp, uint16(code))
 	ext.Error.Set(sp, code >= http.StatusInternalServerError)
 	sp.Finish()
diff --git a/trace/sqs/message.go b/client/sqs/message.go
similarity index 100%
rename from trace/sqs/message.go
rename to client/sqs/message.go
diff --git a/trace/sqs/message_test.go b/client/sqs/message_test.go
similarity index 100%
rename from trace/sqs/message_test.go
rename to client/sqs/message_test.go
diff --git a/trace/sqs/publisher.go b/client/sqs/publisher.go
similarity index 100%
rename from trace/sqs/publisher.go
rename to client/sqs/publisher.go
diff --git a/trace/sqs/publisher_test.go b/client/sqs/publisher_test.go
similarity index 100%
rename from trace/sqs/publisher_test.go
rename to client/sqs/publisher_test.go
diff --git a/async/amqp/amqp.go b/component/async/amqp/amqp.go
similarity index 99%
rename from async/amqp/amqp.go
rename to component/async/amqp/amqp.go
index f5029c638..aefb6fd82 100644
--- a/async/amqp/amqp.go
+++ b/component/async/amqp/amqp.go
@@ -7,7 +7,7 @@ import (
 	"net"
 	"time"
 
-	"github.com/beatlabs/patron/async"
+	"github.com/beatlabs/patron/component/async"
 	"github.com/beatlabs/patron/correlation"
 	"github.com/beatlabs/patron/encoding"
 	patronErrors "github.com/beatlabs/patron/errors"
diff --git a/async/amqp/amqp_test.go b/component/async/amqp/amqp_test.go
similarity index 100%
rename from async/amqp/amqp_test.go
rename to component/async/amqp/amqp_test.go
diff --git a/async/amqp/option.go b/component/async/amqp/option.go
similarity index 100%
rename from async/amqp/option.go
rename to component/async/amqp/option.go
diff --git a/async/amqp/option_test.go b/component/async/amqp/option_test.go
similarity index 100%
rename from async/amqp/option_test.go
rename to component/async/amqp/option_test.go
diff --git a/async/async.go b/component/async/async.go
similarity index 100%
rename from async/async.go
rename to component/async/async.go
diff --git a/async/async_test.go b/component/async/async_test.go
similarity index 100%
rename from async/async_test.go
rename to component/async/async_test.go
diff --git a/async/component.go b/component/async/component.go
similarity index 100%
rename from async/component.go
rename to component/async/component.go
diff --git a/async/component_test.go b/component/async/component_test.go
similarity index 100%
rename from async/component_test.go
rename to component/async/component_test.go
diff --git a/async/kafka/group/group.go b/component/async/kafka/group/group.go
similarity index 97%
rename from async/kafka/group/group.go
rename to component/async/kafka/group/group.go
index ce94e678f..0e6c52efc 100644
--- a/async/kafka/group/group.go
+++ b/component/async/kafka/group/group.go
@@ -6,8 +6,8 @@ import (
 	"fmt"
 
 	"github.com/Shopify/sarama"
-	"github.com/beatlabs/patron/async"
-	"github.com/beatlabs/patron/async/kafka"
+	"github.com/beatlabs/patron/component/async"
+	"github.com/beatlabs/patron/component/async/kafka"
 	"github.com/beatlabs/patron/internal/validation"
 	"github.com/beatlabs/patron/log"
 	"github.com/opentracing/opentracing-go"
diff --git a/async/kafka/kafka.go b/component/async/kafka/kafka.go
similarity index 99%
rename from async/kafka/kafka.go
rename to component/async/kafka/kafka.go
index 7533af669..28ec03e0f 100644
--- a/async/kafka/kafka.go
+++ b/component/async/kafka/kafka.go
@@ -8,7 +8,7 @@ import (
 	"strconv"
 
 	"github.com/Shopify/sarama"
-	"github.com/beatlabs/patron/async"
+	"github.com/beatlabs/patron/component/async"
 	"github.com/beatlabs/patron/correlation"
 	"github.com/beatlabs/patron/encoding"
 	"github.com/beatlabs/patron/log"
diff --git a/async/kafka/option.go b/component/async/kafka/option.go
similarity index 100%
rename from async/kafka/option.go
rename to component/async/kafka/option.go
diff --git a/async/kafka/option_test.go b/component/async/kafka/option_test.go
similarity index 100%
rename from async/kafka/option_test.go
rename to component/async/kafka/option_test.go
diff --git a/async/kafka/simple/simple.go b/component/async/kafka/simple/simple.go
similarity index 97%
rename from async/kafka/simple/simple.go
rename to component/async/kafka/simple/simple.go
index ac0c234dc..6f5f8fda7 100644
--- a/async/kafka/simple/simple.go
+++ b/component/async/kafka/simple/simple.go
@@ -6,8 +6,8 @@ import (
 	"fmt"
 
 	"github.com/Shopify/sarama"
-	"github.com/beatlabs/patron/async"
-	"github.com/beatlabs/patron/async/kafka"
+	"github.com/beatlabs/patron/component/async"
+	"github.com/beatlabs/patron/component/async/kafka"
 	"github.com/beatlabs/patron/internal/validation"
 	"github.com/beatlabs/patron/log"
 )
diff --git a/async/sqs/option.go b/component/async/sqs/option.go
similarity index 100%
rename from async/sqs/option.go
rename to component/async/sqs/option.go
diff --git a/async/sqs/option_test.go b/component/async/sqs/option_test.go
similarity index 100%
rename from async/sqs/option_test.go
rename to component/async/sqs/option_test.go
diff --git a/async/sqs/sqs.go b/component/async/sqs/sqs.go
similarity index 99%
rename from async/sqs/sqs.go
rename to component/async/sqs/sqs.go
index 4d2ee639c..b9a9300dc 100644
--- a/async/sqs/sqs.go
+++ b/component/async/sqs/sqs.go
@@ -10,7 +10,7 @@ import (
 	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/service/sqs"
 	"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
-	"github.com/beatlabs/patron/async"
+	"github.com/beatlabs/patron/component/async"
 	"github.com/beatlabs/patron/correlation"
 	"github.com/beatlabs/patron/encoding"
 	"github.com/beatlabs/patron/encoding/json"
diff --git a/async/sqs/sqs_test.go b/component/async/sqs/sqs_test.go
similarity index 100%
rename from async/sqs/sqs_test.go
rename to component/async/sqs/sqs_test.go
diff --git a/sync/http/alive.go b/component/http/alive.go
similarity index 100%
rename from sync/http/alive.go
rename to component/http/alive.go
diff --git a/sync/http/alive_test.go b/component/http/alive_test.go
similarity index 100%
rename from sync/http/alive_test.go
rename to component/http/alive_test.go
diff --git a/sync/http/auth/apikey/apikey.go b/component/http/auth/apikey/apikey.go
similarity index 100%
rename from sync/http/auth/apikey/apikey.go
rename to component/http/auth/apikey/apikey.go
diff --git a/sync/http/auth/apikey/apikey_test.go b/component/http/auth/apikey/apikey_test.go
similarity index 100%
rename from sync/http/auth/apikey/apikey_test.go
rename to component/http/auth/apikey/apikey_test.go
diff --git a/sync/http/auth/auth.go b/component/http/auth/auth.go
similarity index 100%
rename from sync/http/auth/auth.go
rename to component/http/auth/auth.go
diff --git a/sync/http/component.go b/component/http/component.go
similarity index 100%
rename from sync/http/component.go
rename to component/http/component.go
diff --git a/sync/http/component_test.go b/component/http/component_test.go
similarity index 100%
rename from sync/http/component_test.go
rename to component/http/component_test.go
diff --git a/sync/http/errors.go b/component/http/errors.go
similarity index 100%
rename from sync/http/errors.go
rename to component/http/errors.go
diff --git a/sync/http/errors_test.go b/component/http/errors_test.go
similarity index 100%
rename from sync/http/errors_test.go
rename to component/http/errors_test.go
diff --git a/sync/http/handler.go b/component/http/handler.go
similarity index 95%
rename from sync/http/handler.go
rename to component/http/handler.go
index e6d72d8b1..a87c398b9 100644
--- a/sync/http/handler.go
+++ b/component/http/handler.go
@@ -10,11 +10,10 @@ import (
 	"github.com/beatlabs/patron/encoding/json"
 	"github.com/beatlabs/patron/encoding/protobuf"
 	"github.com/beatlabs/patron/log"
-	"github.com/beatlabs/patron/sync"
 	"github.com/julienschmidt/httprouter"
 )
 
-func handler(hnd sync.ProcessorFunc) http.HandlerFunc {
+func handler(hnd ProcessorFunc) http.HandlerFunc {
 
 	return func(w http.ResponseWriter, r *http.Request) {
 
@@ -37,7 +36,7 @@ func handler(hnd sync.ProcessorFunc) http.HandlerFunc {
 
 		h := extractHeaders(r)
 
-		req := sync.NewRequest(f, r.Body, h, dec)
+		req := NewRequest(f, r.Body, h, dec)
 		rsp, err := hnd(ctx, req)
 		if err != nil {
 			handleError(logger, w, enc, err)
@@ -123,7 +122,7 @@ func extractHeaders(r *http.Request) map[string]string {
 	return h
 }
 
-func handleSuccess(w http.ResponseWriter, r *http.Request, rsp *sync.Response, enc encoding.EncodeFunc) error {
+func handleSuccess(w http.ResponseWriter, r *http.Request, rsp *Response, enc encoding.EncodeFunc) error {
 	if rsp == nil {
 		w.WriteHeader(http.StatusNoContent)
 		return nil
diff --git a/sync/sync.go b/component/http/http.go
similarity index 98%
rename from sync/sync.go
rename to component/http/http.go
index d397f9df7..747dfa3ab 100644
--- a/sync/sync.go
+++ b/component/http/http.go
@@ -1,4 +1,4 @@
-package sync
+package http
 
 import (
 	"context"
diff --git a/sync/http/metric.go b/component/http/metric.go
similarity index 100%
rename from sync/http/metric.go
rename to component/http/metric.go
diff --git a/sync/http/metric_test.go b/component/http/metric_test.go
similarity index 100%
rename from sync/http/metric_test.go
rename to component/http/metric_test.go
diff --git a/sync/http/middleware.go b/component/http/middleware.go
similarity index 78%
rename from sync/http/middleware.go
rename to component/http/middleware.go
index fbaedc2de..241ce96de 100644
--- a/sync/http/middleware.go
+++ b/component/http/middleware.go
@@ -5,11 +5,17 @@ import (
 	"net/http"
 	"strings"
 
+	"github.com/beatlabs/patron/component/http/auth"
 	"github.com/beatlabs/patron/correlation"
 	"github.com/beatlabs/patron/log"
-	"github.com/beatlabs/patron/sync/http/auth"
-	trace_http "github.com/beatlabs/patron/trace/http"
+	"github.com/beatlabs/patron/trace"
 	"github.com/google/uuid"
+	"github.com/opentracing/opentracing-go"
+	"github.com/opentracing/opentracing-go/ext"
+)
+
+const (
+	serverComponent = "http-server"
 )
 
 type responseWriter struct {
@@ -108,10 +114,10 @@ func NewLoggingTracingMiddleware(path string) MiddlewareFunc {
 	return func(next http.Handler) http.Handler {
 		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 			corID := getOrSetCorrelationID(r.Header)
-			sp, r := trace_http.Span(path, corID, r)
+			sp, r := span(path, corID, r)
 			lw := newResponseWriter(w)
 			next.ServeHTTP(lw, r)
-			trace_http.FinishSpan(sp, lw.Status())
+			finishSpan(sp, lw.Status())
 			logRequestResponse(corID, lw, r)
 		})
 	}
@@ -169,3 +175,27 @@ func getOrSetCorrelationID(h http.Header) string {
 	}
 	return cor[0]
 }
+
+func span(path, corID string, r *http.Request) (opentracing.Span, *http.Request) {
+	ctx, err := opentracing.GlobalTracer().Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header))
+	if err != nil && err != opentracing.ErrSpanContextNotFound {
+		log.Errorf("failed to extract HTTP span: %v", err)
+	}
+	sp := opentracing.StartSpan(opName(r.Method, path), ext.RPCServerOption(ctx))
+	ext.HTTPMethod.Set(sp, r.Method)
+	ext.HTTPUrl.Set(sp, r.URL.String())
+	ext.Component.Set(sp, serverComponent)
+	sp.SetTag(trace.VersionTag, trace.Version)
+	sp.SetTag(correlation.ID, corID)
+	return sp, r.WithContext(opentracing.ContextWithSpan(r.Context(), sp))
+}
+
+func finishSpan(sp opentracing.Span, code int) {
+	ext.HTTPStatusCode.Set(sp, uint16(code))
+	ext.Error.Set(sp, code >= http.StatusInternalServerError)
+	sp.Finish()
+}
+
+func opName(method, path string) string {
+	return method + " " + path
+}
diff --git a/sync/http/middleware_test.go b/component/http/middleware_test.go
similarity index 100%
rename from sync/http/middleware_test.go
rename to component/http/middleware_test.go
diff --git a/sync/http/profiling.go b/component/http/profiling.go
similarity index 100%
rename from sync/http/profiling.go
rename to component/http/profiling.go
diff --git a/sync/http/profiling_test.go b/component/http/profiling_test.go
similarity index 100%
rename from sync/http/profiling_test.go
rename to component/http/profiling_test.go
diff --git a/sync/http/ready.go b/component/http/ready.go
similarity index 100%
rename from sync/http/ready.go
rename to component/http/ready.go
diff --git a/sync/http/ready_test.go b/component/http/ready_test.go
similarity index 100%
rename from sync/http/ready_test.go
rename to component/http/ready_test.go
diff --git a/sync/http/route.go b/component/http/route.go
similarity index 96%
rename from sync/http/route.go
rename to component/http/route.go
index eb150d928..d84473179 100644
--- a/sync/http/route.go
+++ b/component/http/route.go
@@ -6,9 +6,8 @@ import (
 	"net/http"
 	"strings"
 
+	"github.com/beatlabs/patron/component/http/auth"
 	errs "github.com/beatlabs/patron/errors"
-	"github.com/beatlabs/patron/sync"
-	"github.com/beatlabs/patron/sync/http/auth"
 )
 
 // Route definition of a HTTP route.
@@ -152,7 +151,7 @@ func NewRawRouteBuilder(path string, handler http.HandlerFunc) *RouteBuilder {
 }
 
 // NewRouteBuilder constructor.
-func NewRouteBuilder(path string, processor sync.ProcessorFunc) *RouteBuilder {
+func NewRouteBuilder(path string, processor ProcessorFunc) *RouteBuilder {
 
 	var err error
 
diff --git a/sync/http/testdata/server.key b/component/http/testdata/server.key
similarity index 100%
rename from sync/http/testdata/server.key
rename to component/http/testdata/server.key
diff --git a/sync/http/testdata/server.pem b/component/http/testdata/server.pem
similarity index 100%
rename from sync/http/testdata/server.pem
rename to component/http/testdata/server.pem
diff --git a/examples/fifth/main.go b/examples/fifth/main.go
index 15edf71e0..1b83e394d 100644
--- a/examples/fifth/main.go
+++ b/examples/fifth/main.go
@@ -12,9 +12,9 @@ import (
 	"github.com/aws/aws-sdk-go/service/sqs"
 	"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
 	"github.com/beatlabs/patron"
-	"github.com/beatlabs/patron/async"
-	patronsqs "github.com/beatlabs/patron/async/sqs"
 	patrongrpc "github.com/beatlabs/patron/client/grpc"
+	"github.com/beatlabs/patron/component/async"
+	patronsqs "github.com/beatlabs/patron/component/async/sqs"
 	"github.com/beatlabs/patron/component/grpc/greeter"
 	"github.com/beatlabs/patron/examples"
 	"github.com/beatlabs/patron/log"
diff --git a/examples/first/main.go b/examples/first/main.go
index fd5f5fe71..a9f4d1312 100644
--- a/examples/first/main.go
+++ b/examples/first/main.go
@@ -9,12 +9,11 @@ import (
 	"time"
 
 	"github.com/beatlabs/patron"
+	clienthttp "github.com/beatlabs/patron/client/http"
+	patronhttp "github.com/beatlabs/patron/component/http"
 	"github.com/beatlabs/patron/encoding/protobuf"
 	"github.com/beatlabs/patron/examples"
 	"github.com/beatlabs/patron/log"
-	"github.com/beatlabs/patron/sync"
-	patronhttp "github.com/beatlabs/patron/sync/http"
-	tracehttp "github.com/beatlabs/patron/trace/http"
 )
 
 func init() {
@@ -68,7 +67,7 @@ func main() {
 	}
 }
 
-func first(ctx context.Context, req *sync.Request) (*sync.Response, error) {
+func first(ctx context.Context, req *patronhttp.Request) (*patronhttp.Response, error) {
 
 	var u examples.User
 
@@ -89,7 +88,7 @@ func first(ctx context.Context, req *sync.Request) (*sync.Response, error) {
 	secondRouteReq.Header.Add("Content-Type", protobuf.Type)
 	secondRouteReq.Header.Add("Accept", protobuf.Type)
 	secondRouteReq.Header.Add("Authorization", "Apikey 123456")
-	cl, err := tracehttp.New(tracehttp.Timeout(5 * time.Second))
+	cl, err := clienthttp.New(clienthttp.Timeout(5 * time.Second))
 	if err != nil {
 		return nil, err
 	}
@@ -99,5 +98,5 @@ func first(ctx context.Context, req *sync.Request) (*sync.Response, error) {
 	}
 
 	log.FromContext(ctx).Infof("request processed: %s %s", u.GetFirstname(), u.GetLastname())
-	return sync.NewResponse(fmt.Sprintf("got %s from second HTTP route", rsp.Status)), nil
+	return patronhttp.NewResponse(fmt.Sprintf("got %s from second HTTP route", rsp.Status)), nil
 }
diff --git a/examples/fourth/main.go b/examples/fourth/main.go
index 490305be7..4ffeb292f 100644
--- a/examples/fourth/main.go
+++ b/examples/fourth/main.go
@@ -15,13 +15,13 @@ import (
 	"github.com/aws/aws-sdk-go/service/sqs"
 	"github.com/aws/aws-sdk-go/service/sqs/sqsiface"
 	"github.com/beatlabs/patron"
-	"github.com/beatlabs/patron/async"
-	"github.com/beatlabs/patron/async/amqp"
+	patronsns "github.com/beatlabs/patron/client/sns"
+	patronsqs "github.com/beatlabs/patron/client/sqs"
+	"github.com/beatlabs/patron/component/async"
+	"github.com/beatlabs/patron/component/async/amqp"
 	"github.com/beatlabs/patron/encoding/json"
 	"github.com/beatlabs/patron/examples"
 	"github.com/beatlabs/patron/log"
-	patronsns "github.com/beatlabs/patron/trace/sns"
-	patronsqs "github.com/beatlabs/patron/trace/sqs"
 	oamqp "github.com/streadway/amqp"
 )
 
diff --git a/examples/second/main.go b/examples/second/main.go
index ed2843376..904ace7f6 100644
--- a/examples/second/main.go
+++ b/examples/second/main.go
@@ -8,13 +8,12 @@ import (
 	"time"
 
 	"github.com/beatlabs/patron"
+	clienthttp "github.com/beatlabs/patron/client/http"
+	"github.com/beatlabs/patron/client/kafka"
+	patronhttp "github.com/beatlabs/patron/component/http"
+	"github.com/beatlabs/patron/component/http/auth/apikey"
 	"github.com/beatlabs/patron/examples"
 	"github.com/beatlabs/patron/log"
-	"github.com/beatlabs/patron/sync"
-	patronhttp "github.com/beatlabs/patron/sync/http"
-	"github.com/beatlabs/patron/sync/http/auth/apikey"
-	tracehttp "github.com/beatlabs/patron/trace/http"
-	"github.com/beatlabs/patron/trace/kafka"
 )
 
 const (
@@ -84,7 +83,7 @@ func newHTTPComponent(kafkaBroker, topic, url string) (*httpComponent, error) {
 	return &httpComponent{prd: prd, topic: topic}, nil
 }
 
-func (hc *httpComponent) second(ctx context.Context, req *sync.Request) (*sync.Response, error) {
+func (hc *httpComponent) second(ctx context.Context, req *patronhttp.Request) (*patronhttp.Response, error) {
 
 	var u examples.User
 	err := req.Decode(&u)
@@ -96,7 +95,7 @@ func (hc *httpComponent) second(ctx context.Context, req *sync.Request) (*sync.R
 	if err != nil {
 		return nil, fmt.Errorf("failed to create request for www.google.com: %w", err)
 	}
-	cl, err := tracehttp.New(tracehttp.Timeout(5 * time.Second))
+	cl, err := clienthttp.New(clienthttp.Timeout(5 * time.Second))
 	if err != nil {
 		return nil, err
 	}
diff --git a/examples/third/main.go b/examples/third/main.go
index bd2978e92..36481498d 100644
--- a/examples/third/main.go
+++ b/examples/third/main.go
@@ -7,13 +7,13 @@ import (
 	"time"
 
 	"github.com/beatlabs/patron"
-	"github.com/beatlabs/patron/async"
-	"github.com/beatlabs/patron/async/kafka"
-	"github.com/beatlabs/patron/async/kafka/group"
+	"github.com/beatlabs/patron/client/amqp"
+	"github.com/beatlabs/patron/component/async"
+	"github.com/beatlabs/patron/component/async/kafka"
+	"github.com/beatlabs/patron/component/async/kafka/group"
 	"github.com/beatlabs/patron/encoding/json"
 	"github.com/beatlabs/patron/examples"
 	"github.com/beatlabs/patron/log"
-	"github.com/beatlabs/patron/trace/amqp"
 )
 
 const (
diff --git a/service.go b/service.go
index 320a5cfea..a1cf9b11d 100644
--- a/service.go
+++ b/service.go
@@ -10,10 +10,10 @@ import (
 	"sync"
 	"syscall"
 
+	"github.com/beatlabs/patron/component/http"
 	patronErrors "github.com/beatlabs/patron/errors"
 	"github.com/beatlabs/patron/log"
 	"github.com/beatlabs/patron/log/zerolog"
-	"github.com/beatlabs/patron/sync/http"
 	"github.com/beatlabs/patron/trace"
 	jaeger "github.com/uber/jaeger-client-go"
 )


Test patch:
diff --git a/trace/http/http_test.go b/client/http/http_test.go
similarity index 97%
rename from trace/http/http_test.go
rename to client/http/http_test.go
index 36adfd284..7614775b7 100644
--- a/trace/http/http_test.go
+++ b/client/http/http_test.go
@@ -101,19 +101,19 @@ func TestHTTPStartFinishSpan(t *testing.T) {
 	opentracing.SetGlobalTracer(mtr)
 	req, err := http.NewRequest("GET", "/", nil)
 	assert.NoError(t, err)
-	sp, req := Span("/", "corID", req)
+	sp, req := span("/", "corID", req)
 	assert.NotNil(t, sp)
 	assert.NotNil(t, req)
 	assert.IsType(t, &mocktracer.MockSpan{}, sp)
 	jsp := sp.(*mocktracer.MockSpan)
 	assert.NotNil(t, jsp)
 	assert.Equal(t, "GET /", jsp.OperationName)
-	FinishSpan(jsp, 200)
+	finishSpan(jsp, 200)
 	assert.NotNil(t, jsp)
 	rawSpan := mtr.FinishedSpans()[0]
 	assert.Equal(t, map[string]interface{}{
 		"span.kind":        ext.SpanKindRPCServerEnum,
-		"component":        "http",
+		"component":        "http-client",
 		"error":            false,
 		"http.method":      "GET",
 		"http.status_code": uint16(200),
diff --git a/trace/http/option.go b/client/http/option.go
similarity index 100%
rename from trace/http/option.go
rename to client/http/option.go
diff --git a/trace/kafka/builder.go b/client/kafka/builder.go
similarity index 100%
rename from trace/kafka/builder.go
rename to client/kafka/builder.go
diff --git a/trace/kafka/builder_test.go b/client/kafka/builder_test.go
similarity index 100%
rename from trace/kafka/builder_test.go
rename to client/kafka/builder_test.go
diff --git a/trace/kafka/kafka.go b/client/kafka/kafka.go
similarity index 100%
rename from trace/kafka/kafka.go
rename to client/kafka/kafka.go
diff --git a/trace/kafka/kafka_test.go b/client/kafka/kafka_test.go
similarity index 100%
rename from trace/kafka/kafka_test.go
rename to client/kafka/kafka_test.go
diff --git a/trace/redis/redis.go b/client/redis/redis.go
similarity index 100%
rename from trace/redis/redis.go
rename to client/redis/redis.go
diff --git a/trace/redis/redis_test.go b/client/redis/redis_test.go
similarity index 100%
rename from trace/redis/redis_test.go
rename to client/redis/redis_test.go
diff --git a/trace/sns/integration_test.go b/client/sns/integration_test.go
similarity index 100%
rename from trace/sns/integration_test.go
rename to client/sns/integration_test.go
diff --git a/trace/sns/message.go b/client/sns/message.go
similarity index 100%
rename from trace/sns/message.go
rename to client/sns/message.go
diff --git a/trace/sns/message_test.go b/client/sns/message_test.go
similarity index 100%
rename from trace/sns/message_test.go
rename to client/sns/message_test.go
diff --git a/trace/sns/publisher.go b/client/sns/publisher.go
similarity index 100%
rename from trace/sns/publisher.go
rename to client/sns/publisher.go
diff --git a/trace/sns/publisher_test.go b/client/sns/publisher_test.go
similarity index 100%
rename from trace/sns/publisher_test.go
rename to client/sns/publisher_test.go
diff --git a/trace/sql/integration_test.go b/client/sql/integration_test.go
similarity index 100%
rename from trace/sql/integration_test.go
rename to client/sql/integration_test.go
diff --git a/trace/sql/sql.go b/client/sql/sql.go
similarity index 100%
rename from trace/sql/sql.go
rename to client/sql/sql.go
diff --git a/trace/sql/sql_test.go b/client/sql/sql_test.go
similarity index 100%
rename from trace/sql/sql_test.go
rename to client/sql/sql_test.go
diff --git a/trace/sqs/integration_test.go b/client/sqs/integration_test.go
similarity index 99%
rename from trace/sqs/integration_test.go
rename to client/sqs/integration_test.go
index 939e3cbce..e8643c1e5 100644
--- a/trace/sqs/integration_test.go
+++ b/client/sqs/integration_test.go
@@ -88,7 +88,6 @@ func Test_Publish_Message(t *testing.T) {
 }
 
 func createAPI(t *testing.T) sqsiface.SQSAPI {
-
 	sess, err := session.NewSession(
 		aws.NewConfig().
 			WithEndpoint(testSqsEndpoint).
diff --git a/async/kafka/group/group_test.go b/component/async/kafka/group/group_test.go
similarity index 98%
rename from async/kafka/group/group_test.go
rename to component/async/kafka/group/group_test.go
index 1745c1084..009f2dce1 100644
--- a/async/kafka/group/group_test.go
+++ b/component/async/kafka/group/group_test.go
@@ -7,8 +7,8 @@ import (
 	"time"
 
 	"github.com/Shopify/sarama"
-	"github.com/beatlabs/patron/async"
-	"github.com/beatlabs/patron/async/kafka"
+	"github.com/beatlabs/patron/component/async"
+	"github.com/beatlabs/patron/component/async/kafka"
 	"github.com/beatlabs/patron/encoding"
 	"github.com/beatlabs/patron/encoding/json"
 	"github.com/stretchr/testify/assert"
diff --git a/async/kafka/kafka_test.go b/component/async/kafka/kafka_test.go
similarity index 99%
rename from async/kafka/kafka_test.go
rename to component/async/kafka/kafka_test.go
index 6ba4dba95..adcf8b495 100644
--- a/async/kafka/kafka_test.go
+++ b/component/async/kafka/kafka_test.go
@@ -12,7 +12,7 @@ import (
 	"time"
 
 	"github.com/Shopify/sarama"
-	"github.com/beatlabs/patron/async"
+	"github.com/beatlabs/patron/component/async"
 	"github.com/beatlabs/patron/correlation"
 	"github.com/beatlabs/patron/encoding"
 	patron_json "github.com/beatlabs/patron/encoding/json"
diff --git a/async/kafka/simple/simple_test.go b/component/async/kafka/simple/simple_test.go
similarity index 98%
rename from async/kafka/simple/simple_test.go
rename to component/async/kafka/simple/simple_test.go
index 08688e670..e3234af45 100644
--- a/async/kafka/simple/simple_test.go
+++ b/component/async/kafka/simple/simple_test.go
@@ -5,8 +5,8 @@ import (
 	"testing"
 
 	"github.com/Shopify/sarama"
-	"github.com/beatlabs/patron/async"
-	"github.com/beatlabs/patron/async/kafka"
+	"github.com/beatlabs/patron/component/async"
+	"github.com/beatlabs/patron/component/async/kafka"
 	"github.com/stretchr/testify/assert"
 )
 
diff --git a/sync/http/handler_test.go b/component/http/handler_test.go
similarity index 95%
rename from sync/http/handler_test.go
rename to component/http/handler_test.go
index 2eb719eb7..0872aa725 100644
--- a/sync/http/handler_test.go
+++ b/component/http/handler_test.go
@@ -12,7 +12,6 @@ import (
 	"github.com/beatlabs/patron/encoding/json"
 	"github.com/beatlabs/patron/encoding/protobuf"
 	"github.com/beatlabs/patron/log"
-	"github.com/beatlabs/patron/sync"
 	"github.com/julienschmidt/httprouter"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
@@ -125,18 +124,18 @@ func Test_handleSuccess(t *testing.T) {
 	assert.NoError(t, err)
 	post, err := http.NewRequest(http.MethodPost, "/", nil)
 	assert.NoError(t, err)
-	jsonRsp := sync.NewResponse(struct {
+	jsonRsp := NewResponse(struct {
 		Name    string
 		Address string
 	}{"Sotiris", "Athens"})
-	jsonEncodeFailRsp := sync.NewResponse(struct {
+	jsonEncodeFailRsp := NewResponse(struct {
 		Name    chan bool
 		Address string
 	}{nil, "Athens"})
 
 	type args struct {
 		req *http.Request
-		rsp *sync.Response
+		rsp *Response
 		enc encoding.EncodeFunc
 	}
 	tests := []struct {
@@ -200,11 +199,11 @@ type testHandler struct {
 	resp interface{}
 }
 
-func (th testHandler) Process(ctx context.Context, req *sync.Request) (*sync.Response, error) {
+func (th testHandler) Process(ctx context.Context, req *Request) (*Response, error) {
 	if th.err {
 		return nil, errors.New("TEST")
 	}
-	return sync.NewResponse(th.resp), nil
+	return NewResponse(th.resp), nil
 }
 
 func Test_handler(t *testing.T) {
@@ -223,7 +222,7 @@ func Test_handler(t *testing.T) {
 	// failure handling
 	type args struct {
 		req *http.Request
-		hnd sync.ProcessorFunc
+		hnd ProcessorFunc
 	}
 	tests := []struct {
 		name         string
@@ -273,7 +272,7 @@ func Test_extractParams(t *testing.T) {
 	req.Header.Set(encoding.AcceptHeader, json.Type)
 	var fields map[string]string
 
-	proc := func(_ context.Context, req *sync.Request) (*sync.Response, error) {
+	proc := func(_ context.Context, req *Request) (*Response, error) {
 		fields = req.Fields
 		return nil, nil
 	}
diff --git a/sync/sync_test.go b/component/http/http_test.go
similarity index 98%
rename from sync/sync_test.go
rename to component/http/http_test.go
index 86f4c14ff..b2f155ac1 100644
--- a/sync/sync_test.go
+++ b/component/http/http_test.go
@@ -1,4 +1,4 @@
-package sync
+package http
 
 import (
 	"bytes"
diff --git a/sync/http/route_test.go b/component/http/route_test.go
similarity index 96%
rename from sync/http/route_test.go
rename to component/http/route_test.go
index 6d49eeb3d..35712e3f4 100644
--- a/sync/http/route_test.go
+++ b/component/http/route_test.go
@@ -5,8 +5,7 @@ import (
 	"net/http"
 	"testing"
 
-	"github.com/beatlabs/patron/sync"
-	"github.com/beatlabs/patron/sync/http/auth"
+	"github.com/beatlabs/patron/component/http/auth"
 	"github.com/stretchr/testify/assert"
 )
 
@@ -160,7 +159,7 @@ func TestRouteBuilder_WithAuth(t *testing.T) {
 
 func TestRouteBuilder_Build(t *testing.T) {
 	mockAuth := &MockAuthenticator{}
-	mockProcessor := func(context.Context, *sync.Request) (*sync.Response, error) { return nil, nil }
+	mockProcessor := func(context.Context, *Request) (*Response, error) { return nil, nil }
 	middleware := func(next http.Handler) http.Handler { return next }
 	type fields struct {
 		path          string
@@ -222,10 +221,10 @@ func TestNewRawRouteBuilder(t *testing.T) {
 }
 
 func TestNewRouteBuilder(t *testing.T) {
-	mockProcessor := func(context.Context, *sync.Request) (*sync.Response, error) { return nil, nil }
+	mockProcessor := func(context.Context, *Request) (*Response, error) { return nil, nil }
 	type args struct {
 		path      string
-		processor sync.ProcessorFunc
+		processor ProcessorFunc
 	}
 	tests := map[string]struct {
 		args        args
diff --git a/service_test.go b/service_test.go
index fc8ceb2db..8e47a9c23 100644
--- a/service_test.go
+++ b/service_test.go
@@ -9,8 +9,8 @@ import (
 	"strconv"
 	"testing"
 
+	phttp "github.com/beatlabs/patron/component/http"
 	"github.com/beatlabs/patron/log"
-	phttp "github.com/beatlabs/patron/sync/http"
 	"github.com/stretchr/testify/assert"
 )