diff --git a/segmentio.go b/segmentio.go index a1e8ae9..261fac6 100644 --- a/segmentio.go +++ b/segmentio.go @@ -177,8 +177,10 @@ func (k *kBroker) Publish(topic string, msg *broker.Message, opts ...broker.Publ return err } kmsg := kafka.Message{Value: val} - if key, ok := options.Context.Value(publishKey{}).([]byte); ok && len(key) > 0 { - kmsg.Key = key + if options.Context != nil { + if key, ok := options.Context.Value(publishKey{}).([]byte); ok && len(key) > 0 { + kmsg.Key = key + } } k.Lock()